Re: mp:process-run-function and a blocking foreign call
Tapio Karras <[email protected]> Tue, 29 Nov 2005 14:12:40 -0800
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <[email protected]> |
Hi Steven, FFI calls are blocking by default. That is, they halt the whole Lisp and not just the MP process making the call. To allow other MP process to run during the call, the FFI call needs to release the Lisp heap. Look for the :release-heap keyword of def-foreign-call in http://www.franz.com/support/documentation/7.0/doc/operators/ff/def-foreign-call.htm The additional challenge is to allocate all FFI arguments in static space, so that they don't get moved by the GC as a result of the other MP processes running while the FFI call is in progress. Hope this helps, Tapio > On 11/28/2005 "Steven E. Harris" wrote: > > I am running the Allegro CL 7 Trial Edition on Windows XP, and am > having trouble using the multiprocessing features (via > mp:process-run-function) in conjunction with a blocking foreign > function call. > > Background summary: I have defined foreign function calls out to much > of the Windows Smart Card subsystem and can call on these functions > from CL with ease. All these calls work as expected. The function I'm > working with today is SCardGetStatusChange¹, called on in the manner > sketched here.² > > As discussed in the final paragraph on the second referenced page, > SCardGetStatusChange is a blocking function that is designed to be run > from a dedicated thread -- one which will presumably then communicate > with or start other threads in reaction to certain events. > > I am able to use my wrapped SCardGetStatusChange function just fine > from CL. Running it from the listener, the Allegro CL IDE hangs while > SCardGetStatus change is blocked. That's fine for testing this > specific function, but of course I'd like to actually run the function > in a separate thread. > > Today I attempted to run my card monitoring function in a separate > thread using mp:process-run-function, like so: > > (mp:process-run-function "monitor" #'monitor-changes 4000) > > The function gets run, but the IDE still hangs while it's running. I > tried starting other threads in parallel as well, doing things like > printing random numbers, and while these other threads do get started > they obviously hang while the card monitoring function is running. > > My suspicion is that the foreign function call is to blame for the > thread interference, but I don't know what to investigate next. To > recap, the blocking card monitoring function works properly, but I > can't figure out how to run it in such a way that it doesn't cause > other threads (including those running the IDE) to hang. > > Any advice would be appreciated. > > Footnotes: > ¹ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/scardgetstatuschange.asp > ² http://www.softpedal.net/CodeHelp/SCardGetStatusChange.htm > > -- > Steven E. Harris