On Mon, Mar 25, 2019 at 03:56:30PM +0100, Massimo Nocentini wrote: > Dear list, > > this is my first message so I take the opportunity to greet everyone. > > I'm working on a minimal set of bindings [1] for the microhttpd library [2] > and I'm heading against the following error: > > [panic] callback invoked in non-safe context - execution terminated > > To set the context: the variadic function MHD_start_daemon starts the server > to accept connection and calls back a Scheme function that provides the > content to the client.
Hello Massimo, From the microhttpd documentation, it seems that it will always start a new native thread. The problem here is that CHICKEN can only run inside one native thread and requires complete control of the stack within that thread. When the Scheme callback you passed to MHD_Daemon is called, it is called from the thread which microhttpd starts. It will try to read/write data from the nursery (stack) of a different thread, and on GC it will try to longjmp back to a stack state in a different thread, which is not going to work. CHICKEN's garbage collector does not play well at all with native multithreading. There might be a way to get it to work but it would require some sort of communication between the native threads (all in C), and you'd need to set up a green thread in CHICKEN that handles the response somehow. I don't think this is a good approach. You're probably better off wrapping a different library (or just use Spiffy). Cheers, Peter
signature.asc
Description: PGP signature
_______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
