[m-rev.] diff: implement semaphores on the il backend

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Mar 1 03:53:16 AEDT 2003


On 28-Feb-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> +:- pragma foreign_proc("C#", signal(Semaphore::in, _IO0::di, _IO::uo),
> +		[will_not_call_mercury, thread_safe, promise_pure], "{
> +	System.Threading.Monitor.Enter(Semaphore);
> +	Semaphore.count++;
> +		// XXX I think we only need to do a Pulse.
> +	System.Threading.Monitor.PulseAll(Semaphore);
> +	System.Threading.Monitor.Exit(Semaphore);
> +}").

I too think it is safe to do Pulse() there.

> +:- pragma foreign_proc("C#",
> +		try_wait0(Semaphore::in, Res::out, _IO0::di, _IO::uo),
> +		[will_not_call_mercury, thread_safe, promise_pure], "{
> +	System.Threading.Monitor.Enter(Semaphore);
> +
> +	if (Semaphore.count > 0) {
> +		Semaphore.count--;
> +		System.Threading.Monitor.Exit(Semaphore);
> +		Res = 0;
> +	} else {
> +		System.Threading.Monitor.Exit(Semaphore);
> +		Res = 1;
> +	}

That is broken.  semaphore__try_wait must never block.
You need to use TryEnter() instead of Enter().

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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