[gambit-list] crash on callback from WMI event

Marc Feeley feeley at iro.umontreal.ca
Wed Jun 21 11:36:47 EDT 2006


Tim, if I understand correctly you have 2 OS threads that are  
executing the Scheme code.  This will not work.  You have to imagine  
that the Scheme code is being run by a virtual machine, with a single  
instance of VM registers, a VM stack, etc.  If 2 OS threads are  
executing Scheme code, then they are both accessing the same VM  
resources, leading to corruption and usually a crash.

Here are a couple of ways to solve the problem:

1) Use sockets or named pipes to exchange information between the two  
OS threads.

2) Implement a new Gambit I/O device to represent an event queue.   
One OS thread runs the Scheme code which reads this queue.  The other  
OS thread writes the events to this queue.  This will require changes  
to lib/os_io.c .  I intend to add something like this in the standard  
Gambit distribution, but I haven't gotten around to implementing it  
completely yet (see ___os_device_event_queue_open).

Marc

On 16-Jun-06, at 7:55 PM, Timothy Ritchey wrote:

> I am writing a simple test application that calls out to a custom  
> dll to
> interface with Windows WMI. I am currently trying to get callbacks
> working for WMI Events. I have the following defines for creating  
> an alert:
>
> (define create-alert (c-lambda ((function (wbem-object) int)) void
> "WMICreateAlert"))
> (c-define (wmi-alert-callback alert) ("WBEMOBJ") int  
> "wmi_alert_callback" ""
>    (+ 1 2))
>
> For testing I have the callback return an integer that I printf()  
> in the
> dll. I then call:
>
> (create-alert wmi-alert-callback)
> (read-char)
>
> to create the alert, and wait around for something to happen. When the
> alert is triggered, everything works, and I get back 3 as expected  
> from
> the scheme callback. However, if I put anything more complex in the  
> body
> of wmi-alert-callback (for example (write 3), or (length alert)) The
> application crashes. The debugger is showing that I am not crashing in
> the callback thread, but rather the main thread at line 3965 in
> _kernel.c (I have not yet figured out what the actual function name  
> is):
>
> #undef ___ARG1
>     ___SET_R0(___LBL(12))
>     ___JUMPGENNOTSAFE(___SET_NARGS(0),___FIX(0L))
> ___DEF_SLBL(12,___L12__23__23_kernel_2d_handlers)
> #define ___ARG1 ___R1
> { ___SCMOBJ ___RESULT;
>
>      ...
>      ra1 = ___FP_STK(fp,-___FRAME_STACK_RA); // **** here ****
>      ...
>
> fp is reading as 0x00000000 in the debugger. I seems that I am  
> having a
> problem getting the callback thread to play nicely with the main  
> thread
> in Gambit. I am out of my element here, so any advice would be
> appreciated. Is there something I need to do special to get the main
> Gambit thread to work with callbacks from the Windows subsystem?
>
> Cheers,
> Tim
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list