[gambit-list] FFI, returning values, thread safety
Marc Feeley
feeley at iro.umontreal.ca
Wed Sep 19 10:49:27 EDT 2007
On 19-Sep-07, at 7:41 AM, 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:
Yes.
>
> ___SCMOBJ foo()
> {
> ___SCMOBJ result;
> ___EXT(___CHARSTRING_to_SCMOBJ) ("hello", &result, 0);
> ___release_scmobj (result);
> return result;
> }
Note that it would be much less hassle to write:
(c-declare #<<EOS
char *foo() { return "hello"; }
EOS
)
(define foo (c-lambda () char-string "foo"))
>
> 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?
Threading is implemented in Scheme (using continuations). Operating
system threads are not currently implemented. The context switching
is thus only possible outside of C functions like foo. Consequently
there is no race condition.
Marc
More information about the Gambit-list
mailing list