[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Question on Multithreading from C API
> One other approach is to wrap some scheme code around each request:
>
> (let ([v #f])
> ... code to retrieve value ...
> (thread
> (lambda ()
> (set! v ...)))
>
> Would something like that work for you?
>
Maybe. Since I'm in C at the point the request is being made, I'm
thinking in terms of something like this (pseudocode):
Scheme_Object* my_special_signal(int argc, Scheme_Object** argv)
{
// Based on its first argument (which is the value returned by
// scheme_thread), look up the appropriate condition
// variable
// Do the usual checking
if (! SCHEME_SOMETHINGP(argv[0]))
scheme_raise_exn(blah blah);
sRequest* req = lookup_struct(argv[0]);
req->result = // result part of argv[1], which
// should check exceptions, etc.
pthread_condition(&done_var); // Signal the waiter
return scheme_void;
}
("my_special_signal" is registered as arity 2, etc.)
All code goes through this thunk:
char *e =
"(#%lambda (thunk) "
"(#%with-handlers ([#%void (#%lambda (exn) (#%cons #f exn))]) "
"(#%cons #t (thunk))))";
It seems like I should be able to modify this to call the global "signal"
method. Unforunately, I'm not very familiar with Scheme's macro system
yet, so this may be wrong:
char* e =
"(#%lambda (thunk) "
"(#%my-special-signal (#%get-my-thread-id)
"(#%with-handlers ([#%void (#%lambda (exn) (#%cons
#f exn))]) "
"(#%cons #t (thunk)))))";
And "get-my-thread-id" is either already defined in MzScheme (I'll have to
check the manuals), or could be simply defined as a C function.
Does this look right?
-Brent