chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] microhttpd bindings and FFI


From: Peter Bex
Subject: Re: [Chicken-users] microhttpd bindings and FFI
Date: Mon, 25 Mar 2019 16:17:09 +0100
User-agent: NeoMutt/20170113 (1.7.2)

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

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]