[racket-dev] posting to semaphore from C causes seg fault
On Sep 17, 2011, at 7:32 AM, Matthew Flatt wrote:
> It looks like the call in C might have been in a thread other than the
> thread where Racket was started. In that case, when scheme_post_sema()
> tries to cooperate with the GC, then it would end up with a NULL
> pointer for the Racket GC information of the current thread.
>
> In particular, since you're asking about semaphores, I wonder whether
> you were trying to use Racket semaphores to synchronize OS-level
> threads? If so, it won't work; Racket semaphores only work among Racket
> threads, and you'd have to use OS-level semaphores to synchronize
> OS-level threads.
>
> If you were calling scheme_post_sema() from an OS thread where Racket
> was started, though, then we need to investigate further.
Nope, that's it; I was trying to use scheme_post_sema to synchronize threads.
I spent another few minutes in the docs, and *finally* found the relevant paragraph:
In an embedding application, Racket can co-exist with additional OS-implemented threads, but the additional OS threads must not call any scheme_ function. Only the OS thread representing a particular place can call scheme_ functions. (This restriction is stronger than saying all calls for a given place must be serialized across threads. Racket relies on properties of specific threads to avoid stack overflow and garbage collection.) For the original place, only the OS thread used to call scheme_basic_env can call scheme_ functions. For any other place, only the OS thread that is created by Racket for the place can be used to call scheme_ functions.
So: yes, it was in there. Would it make sense to add a sentence to the beginning of Section 8, Threads, that reads
(This section describes Racket threads. For information on OS threads, see "Racket and OS Threads")
... and rename Inside/1.6, "Racket and Threads", to "Racket and OS Threads" ?
I suppose this means there's no platform-independent synchronization mechanism?
Anyhow, this is clearly not your problem.
Thanks!
John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20110917/c208dff2/attachment.p7s>