[gambit-list] FFI, returning values, thread safety

Guillaume Cartier gcartier at jazzscheme.org
Wed Sep 19 09:12:40 EDT 2007


Michael South wrote:
> I have a question about the C interface. It appears necessary to
> decrement the reference count of ___STILL objects before returning them:
>
> ___SCMOBJ foo()
> {
>   ___SCMOBJ result;
>   ___EXT(___CHARSTRING_to_SCMOBJ) ("hello", &result, 0);
>   ___release_scmobj (result);
>   return result;
> }
>
> Why is there not a race condition between decrementing the reference
> count (___release_scmobj) and returning the result? What if another
> thread wakes up the GC in the meantime?
>   
It's safe because Gambit does not (yet!?) support OS threads and a 
Gambit thread switch cannot occur at this point in your code.

Guillaume



More information about the Gambit-list mailing list