Marc:
Is there any way to add POLLs to C code? There's a C library I'd like to link to a program, but one C routine could possibly take seconds or minutes to run, and Gambit disables interrupts except through POLLs.
Brad
Afficher les réponses par date
On 12/28/05, Bradley Lucier lucier@math.purdue.edu wrote:
Is there any way to add POLLs to C code? There's a C library I'd like to link to a program, but one C routine could possibly take seconds or minutes to run, and Gambit disables interrupts except through POLLs.
You mean that you want an external library to be able to wait on a file descriptor (e.g. using select/poll)? (Speaking about "disabling interrupts" is confusing. Gambit is a user-land process and cannot disable interrupts)
You need to hook into Gambit's main I/O loop. The code to do this is a little confusing because of the need to work across platforms, but you can find it. When the C object is linked into the Gambit code it can access Gambit's functions for manipulating the set of file descriptors to wait on. You'll need to pull in some of Gambit's internal headers, but it'll work.
Also; a few months ago I posted a patch to Beta 14 which changed the event loop to use libevent[1]. Your C code can then then use libevent as normal (except that it shouldn't call the init function) and everything will work perfectly.
[1] http://www.monkey.org/~provos/libevent/
AGL
-- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641
On 12/28/05, Bradley Lucier lucier@math.purdue.edu wrote:
Is there any way to add POLLs to C code? There's a C library I'd like to link to a program, but one C routine could possibly take seconds or minutes to run, and Gambit disables interrupts except through POLLs.
You mean that you want an external library to be able to wait on a file descriptor (e.g. using select/poll)? (Speaking about "disabling interrupts" is confusing. Gambit is a user-land process and cannot disable interrupts)
Actually, no. Gambit masks CNTL-C and allows interrupts only at fixed points in the C code where the state of the Gambit Virtual Machine (GVM) is well known, so if a GC happens things are OK, etc. Gambit checks whether an interrupt is waiting with the POLL macro in gambit.h; this is what I meant by adding POLLs to C code.
Brad
On 28-Dec-05, at 1:50 PM, Bradley Lucier wrote:
Marc:
Is there any way to add POLLs to C code? There's a C library I'd like to link to a program, but one C routine could possibly take seconds or minutes to run, and Gambit disables interrupts except through POLLs.
I see two solutions.
1) if you can modify your C library, add the test "___ps->intr_flag [___INTR_USER] != 0" at appropriate places in the C library to detect when a CTRL-C interrupt is pending, and abort that computation,
2) execute your C library in a separate C thread, and synchronize with that thread.
Marc