[m-rev.] for review: coroutining for parallel conjunctions

Julien Fischer juliensf at cs.mu.OZ.AU
Mon Jul 3 18:54:18 AEST 2006


On Fri, 30 Jun 2006, Peter Wang wrote:

> By the way, is anyone using asm_fast.par.gc on saturn and earth?
> Otherwise I'll change those installations to asm_jump.par.gc, which
> don't suffer from the random errors (somehow related to gcc global
> registers, GC and whether you link with pthreads statically or not
> -- wtf?).

Have you tried this on anything other than Linux?

> Estimated hours taken: 8
> Branches: main
>
> Add coroutining support for dependent parallel conjunctions in lowlevel
> parallel grades.
>
> library/par_builtin.m:
> 	Change definitions of synchronisation primitives so that waiting on a
> 	future causes the current context to be suspended.  Signalling a
> 	future causes all the contexts waiting on the future to be scheduled.
>
> tests/par_conj/Mmakefile:
> 	Actually run dependent parallel conjunction tests since they should
> 	no longer deadlock.
>
> tests/par_conj/*.exp:
> 	Add expected outputs for test cases which didn't have them.
>
> tests/par_conj/*.m:
> 	Add calls to `io.flush_output'.  Without them there were some
> 	spurious failures (to be investigated later).

...

> +    % Because par_builtin.wait has a local label, we may get
> +    % C compilation errors if inlining leads to multiple copies
> +    % of this code.
> +    %
> +    % XXX get rid of this limitation at some stage.
> +    %
> +:- pragma no_inline(par_builtin.wait/2).
>  :- pragma foreign_proc("C",
>      wait(Future::in, Value::out),
>      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
>  "
> -#ifdef MR_THREAD_SAFE
> -# ifdef MR_HAVE_SEMAPHORE_H
> -    sem_wait(&Future->semaphore);
> -    sem_post(&Future->semaphore);
> -    Value = Future->value;
> -# else
> -    pthread_mutex_lock(&Future->mutex);
> -    while (!Future->pass) {
> -        pthread_cond_wait(&Future->cond, &Future->mutex);
> +#if (!defined MR_HIGHLEVEL_CODE) && (defined MR_THREAD_SAFE)
> +
> +    MR_LOCK(&(Future->lock), ""future.wait"");
> +
> +    if (Future->signalled) {
> +        Value = Future->value;
> +        MR_UNLOCK(&(Future->lock), ""future.wait"");
> +    } else {
> +        /*
> +        ** The address of the future can be lost when we resume so save it on
> +        ** top of the stack.
> +        */
> +        MR_incr_sp(1);
> +        MR_sv(1) = (MR_Word) Future;
> +
> +        /*
> +        ** Save this context and put it on the list of suspended contexts for
> +        ** this future.
> +        */
> +        MR_save_context(MR_ENGINE(MR_eng_this_context));
> +        MR_ENGINE(MR_eng_this_context)->MR_ctxt_resume = &&wait_resume;

Does taking the address of a label work in the none grades? (and the reg
ones for that matter).

> +        MR_ENGINE(MR_eng_this_context)->MR_ctxt_next = Future->suspended;
> +        Future->suspended = MR_ENGINE(MR_eng_this_context);
> +
> +        MR_UNLOCK(&(Future->lock), ""future.wait"");
> +        MR_runnext();
> +
> +        assert(0);
> +
> +    wait_resume:
> +
> +        /* Restore the address of the future after resuming. */
> +        Future = (MR_Future *) MR_sv(1);
> +        MR_decr_sp(1);
> +
> +        assert(Future->signalled == 1);
> +        Value = Future->value;
>      }
> -    Value = Future->value;
> -    pthread_mutex_unlock(&Future->mutex);
> -# endif
> +
> +#else
> +
> +    MR_fatal_error(""internal error: par_builtin.wait"");
> +    Value = -1;
> +
>  #endif
>  ").

Julien.
--------------------------------------------------------------------------
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