[m-rev.] for review: hang in lowlevel parallel grade

Peter Wang wangp at students.cs.mu.OZ.AU
Wed Jun 28 19:09:09 AEST 2006


On 2006-06-28, Julien Fischer <juliensf at cs.mu.OZ.AU> wrote:
> 
> On Wed, 28 Jun 2006, Peter Wang wrote:
> 
> >
> > Estimated hours taken: 6
> > Branches: main, release
> >
> > This patch fixes a bug with lowlevel parallel grades.  A program built in such
> > a grade could hang when running with multiple threads.
> >
> > runtime/mercury_context.c:
> > 	After scheduling a Mercury context, use MR_BROADCAST to wake up all
> > 	idle threads instead of MR_SIGNAL, if the newly scheduled context might
> > 	not be accepted for execution by any single woken thread.  The hang
> > 	used to occur when a context was scheduled but the wrong idle thread
> > 	was woken up to execute it (because the context is 'owned' by another
> > 	thread) and promptly went back to idling.
> >
> > runtime/mercury_thread.h:
> > 	Add MR_BROADCAST macros.
> >
> 
> Is there a test case for this?

Here it is.


Index: tests/par_conj/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/par_conj/Mmakefile,v
retrieving revision 1.1
diff -u -r1.1 Mmakefile
--- tests/par_conj/Mmakefile	28 Jun 2006 04:46:21 -0000	1.1
+++ tests/par_conj/Mmakefile	28 Jun 2006 09:06:23 -0000
@@ -40,7 +40,8 @@
 
 INDEP_PAR_CONJ_PROGS = \
 	indep_par_append \
-	indep_par_nested
+	indep_par_nested \
+	threads_hang
 
 ifneq "$(findstring decldebug,$(GRADE))" ""
 	OBJ_PROGS =
@@ -90,6 +91,15 @@
 
 $(OBJ_PROGS:%=%.runtest): %.runtest: %.$(TARGET_OBJ_EXT) ;
 
+# Run threads_hang with multiple OS threads in lowlevel parallel grades.
+# Repeat the test a few times in increase the chances of getting a deadlock.
+ifeq "$(filter hl% java% il%,$(GRADE))" ""
+threads_hang.out: threads_hang
+	for i in 1 2 3 4 5 ; do \
+		MERCURY_OPTIONS=-P10 ./threads_hang 2>&1 > threads_hang.out ;\
+	done
+endif
+
 #-----------------------------------------------------------------------------#
 
 printtests:
Index: tests/par_conj/threads_hang.exp
===================================================================
RCS file: tests/par_conj/threads_hang.exp
diff -N tests/par_conj/threads_hang.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/par_conj/threads_hang.exp	28 Jun 2006 08:50:17 -0000
@@ -0,0 +1 @@
+144
Index: tests/par_conj/threads_hang.m
===================================================================
RCS file: tests/par_conj/threads_hang.m
diff -N tests/par_conj/threads_hang.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/par_conj/threads_hang.m	27 Jun 2006 05:39:13 -0000
@@ -0,0 +1,28 @@
+% In low-level parallel grades, running with many threads could cause
+% the program to deadlock.
+
+:- module threads_hang.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module int.
+
+main(!IO) :-
+    fib(11, F),
+    io.write_int(F, !IO),
+    io.nl(!IO).
+
+:- pred fib(int::in, int::out) is det.
+
+fib(N, F) :-
+    (if N < 2 then
+        F = 1
+    else
+        ( fib(N-1, F1)
+        & fib(N-2, F2)
+        ),
+        F = F1 + F2
+    ).

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list