[m-rev.] for review: don't terminate process until all threads done
Julien Fischer
juliensf at csse.unimelb.edu.au
Mon Apr 30 16:00:48 AEST 2007
On Mon, 30 Apr 2007, Peter Wang wrote:
> Branches: main
>
> Prevent multi-threaded programs from terminating as soon as the main thread
> terminates, i.e. the process should not terminate until all threads started by
> thread.spawn/3 terminate.
Is it worth having a predicate that lets the user disable it?
I think there was a comment somewhere that indicated the reason this
hadn't been implemented was that a good default behaviour hadn't been
decided. (I think this is a reasonable default behaviour.)
I think this is worth announcing in the NEWS file as well.
> This is done by maintaining a a global count of the number of threads started
> by thread.spawn. In low-level C grades the main context will suspend if it
> reaches the global_success label and finds there are other contexts still
> outstanding. The last context to terminate then reschedules the main context
> to resume.
>
> Similarly, in high-level C grades the main thread waits on a condition
> variable, which is signalled by the last thread to terminate.
>
> library/thread.m:
> runtime/mercury_context.c:
> runtime/mercury_thread.c:
> runtime/mercury_thread.h:
> runtime/mercury_wrapper.c:
> As above.
>
> Add some extra assertions related to this.
>
> tests/par_conj/Mmakefile:
> tests/par_conj/thread_barrier.exp:
> tests/par_conj/thread_barrier.m:
> Add test case
...
> only in patch2:
> unchanged:
> --- runtime/mercury_wrapper.c 17 Apr 2007 05:38:10 -0000 1.181
> +++ runtime/mercury_wrapper.c 30 Apr 2007 05:07:34 -0000
> @@ -2358,6 +2358,16 @@
> }
> }
>
> + #if defined(MR_HIGHLEVEL_CODE) && defined(MR_THREAD_SAFE)
> + assert(pthread_self() == MR_primordial_thread);
s/assert/MR_assert/
The rest looks okay (although it looks like part of your diff from the
other day got mixed up in it?).
Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list