[m-rev.] for review: hang in lowlevel parallel grade
Peter Wang
wangp at students.cs.mu.OZ.AU
Wed Jun 28 16:11:27 AEST 2006
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.
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.44
diff -u -r1.44 mercury_context.c
--- runtime/mercury_context.c 9 Mar 2006 08:24:41 -0000 1.44
+++ runtime/mercury_context.c 27 Jun 2006 05:48:21 -0000
@@ -347,7 +347,16 @@
MR_runqueue_head = ctxt;
MR_runqueue_tail = ctxt;
}
- MR_SIGNAL(&MR_runqueue_cond);
+ /*
+ ** Wake one or more threads waiting in MR_do_runnext. If there is a
+ ** possibility that a woken thread might not accept this context then
+ ** we wake up all the waiting threads.
+ */
+ if (ctxt->MR_ctxt_owner_thread == (MercuryThread) NULL) {
+ MR_SIGNAL(&MR_runqueue_cond);
+ } else {
+ MR_BROADCAST(&MR_runqueue_cond);
+ }
MR_UNLOCK(&MR_runqueue_lock, "schedule");
}
Index: runtime/mercury_thread.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_thread.h,v
retrieving revision 1.17
diff -u -r1.17 mercury_thread.h
--- runtime/mercury_thread.h 20 Jun 2005 02:16:44 -0000 1.17
+++ runtime/mercury_thread.h 26 Jun 2006 10:50:35 -0000
@@ -46,6 +46,7 @@
#define MR_UNLOCK(lck, from) pthread_mutex_unlock((lck))
#define MR_SIGNAL(cnd) pthread_cond_signal((cnd))
+ #define MR_BROADCAST(cnd) pthread_cond_broadcast((cnd))
#define MR_WAIT(cnd, mtx) pthread_cond_wait((cnd), (mtx))
#else
#define MR_LOCK(lck, from) \
@@ -67,6 +68,12 @@
: \
pthread_cond_signal((cnd)) \
)
+ #define MR_BROADCAST(cnd) \
+ ( MR_debug_threads ? \
+ MR_cond_broadcast((cnd)) \
+ : \
+ pthread_cond_broadcast((cnd)) \
+ )
#define MR_WAIT(cnd, mtx) \
( MR_debug_threads ? \
MR_cond_wait((cnd), (mtx)) \
@@ -141,6 +148,7 @@
#define MR_UNLOCK(nothing, from) do { } while (0)
#define MR_SIGNAL(nothing) do { } while (0)
+ #define MR_BROADCAST(nothing) do { } while (0)
#define MR_WAIT(no, thing) do { } while (0)
#define MR_OBTAIN_GLOBAL_LOCK(where) do { } while (0)
--------------------------------------------------------------------------
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