|View Issue Details [ Jump to Notes ]||[ Issue History ] [ Print ]|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0000357||mercury||Bug||public||2014-09-02 16:05||2016-10-03 10:58|
|Platform||x86_64||OS||OS X||OS Version||10.9|
|Target Version||15.11||Fixed in Version|
|Summary||0000357: Parallel conjunction broken on OS X|
|Description||Parallel conjunctions are broken on OS X (I used asm_fast.par.gc, but|
this presumably applies to the other grades as well), because although OS X defines the function
sem_init (called from mercury_context.c), it defines it to only return an error.
Possible solutions to this are either to use named semaphores, e.g. with sem_open, or to use
Grand Central Dispatch. (I'm not sure how well the latter would work with GCC though.)
|Tags||No tags attached.|
|Or just condition variables, though presumably they perform worse so we would want to stick to semaphores on better platforms.|
This would have shown up more obviously had the return value of sem_init been checked!
There are also a bunch of calls to various pthread_* functions in the runtime, for example pthread_mutex_init and pthread_attr_init, where the return values are not checked.
I remember some things about writing this code but not others.
In particular I remember choosing semaphores for a very good reason, but I don't remember what that reason was :-(
I'm not sure what should be used instead on OS X. Except that if we want to use GCD, then we should essentially write a different implementation for the N:M threading on OS X, as GCD will (and should) handle this for us. I suspect windows is a similar case as it supports fibers. However that's about all I know of either platform/API.
So I'd recommend trying to replace this with named semaphores, if those are supported/work, or maybe condition variables - again there's a good reason why I didn't use those but I don't know what it is. And in the longer term consider writing an alternative implementation of all this code (maybe keep the work stealing) for OS X.
Using GCD to do the N:M threading is a separate issue; the semaphore implementation in libdispatch is close enough to POSIX unnamed semaphores that it should be easy enough to use as a drop-in replacement. Using GCD in general on OS X is a much larger change.
|Agreed, which is why I said that's a longer term change, and by implication not really part of this bug. However I wasn't aware of the primitives provided by libdispatch so I didn't know that's what you meant when you said GCD. It sounds reasonable to me.|
|Fixed in commit 1fc495c.|
|2014-09-02 16:05||juliensf||New Issue|
|2014-09-02 16:24||wangp||Note Added: 0000779|
|2014-09-02 16:25||juliensf||Note Added: 0000780|
|2015-10-21 10:40||pbone||Target Version||=> 15.11|
|2016-09-29 11:37||juliensf||Assigned To||=> juliensf|
|2016-09-29 11:37||juliensf||Status||new => assigned|
|2016-09-29 14:04||pbone||Note Added: 0000921|
|2016-09-29 14:13||juliensf||Note Added: 0000922|
|2016-09-29 14:24||pbone||Note Added: 0000923|
|2016-10-03 10:58||juliensf||Status||assigned => resolved|
|2016-10-03 10:58||juliensf||Resolution||open => fixed|
|2016-10-03 10:58||juliensf||Note Added: 0000925|