2024-11-22 00:28 AEDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000357mercuryBugpublic2016-10-03 10:58
Reporterjuliensf 
Assigned Tojuliensf 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Platformx86_64OSOS XOS Version10.9
Product Version 
Target Version15.11Fixed in Version 
Summary0000357: Parallel conjunction broken on OS X
DescriptionParallel 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.)
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000779

wangp (developer)

Or just condition variables, though presumably they perform worse so we would want to stick to semaphores on better platforms.

~0000780

juliensf (administrator)

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.

~0000921

pbone (administrator)

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.

~0000922

juliensf (administrator)

Hi Paul,

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.

~0000923

pbone (administrator)

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.

~0000925

juliensf (administrator)

Fixed in commit 1fc495c.
+Notes

-Issue History
Date Modified Username Field Change
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
+Issue History