Changes between Version 3 and Version 4 of Commentary/Rts/Signals


Ignore:
Timestamp:
Mar 4, 2010 6:57:41 PM (4 years ago)
Author:
cygnus
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/Signals

    v3 v4  
    5858 
    5959The solution we use, on both Windows and POSIX systems, is to pass all signals that arrive to the [wiki:Commentary/Rts/IOManager IO Manager] thread.  On POSIX this works by sending the signal number down a pipe, on Windows it works by storing the signal number in a buffer and signaling the IO Manager's `Event` object to wake it up.  The IO Manager thread then wakes up and creates a new thread for the signal handler, before going back to sleep again. 
     60 
     61== RTS Alarm Signals and Foreign Libraries == 
     62 
     63When using foreign libraries through the Haskell FFI, it is important 
     64to ensure that the foreign code is capable of dealing with system call 
     65interrupts due to alarm signals.  For example, in this `strace` output 
     66a `select` call is interrupted, but the foreign C code interprets the 
     67interrupt as an application error and closes a critical file 
     68descriptor: 
     69 
     70{{{ 
     71[pid 22338] send(7, "\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 116, MSG_NOSIGNAL) = 116 
     72[pid 22338] select(8, [7], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted) 
     73[pid 22338] --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- 
     74[pid 22338] sigreturn()                 = ? (mask now []) 
     75[pid 22338] gettimeofday({1267656511, 467069}, NULL) = 0 
     76[pid 22338] stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=3519, ...}) = 0 
     77[pid 22338] write(6, "Communication failed in RPC"..., 176) = 176 
     78[pid 22338] close(7)                    = 0 
     79}}} 
     80 
     81Once the C code was modified to deal with the interrupt properly, it 
     82proceeded correctly: 
     83 
     84{{{ 
     85[pid 23967] send(7, "\f\0\0\0\244\1\0\0\0\0\0\0B\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 536, MSG_NOSIGNAL <unfinished ...> 
     86[pid 23968] <... select resumed> )      = ? ERESTARTNOHAND (To be restarted) 
     87[pid 23968] --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- 
     88[pid 23968] sigreturn()                 = ? (mask now []) 
     89[pid 23968] futex(0x9b52a88, FUTEX_WAIT_PRIVATE, 7, NULL <unfinished ...> 
     90[pid 23967] <... send resumed> )        = 536 
     91[pid 23967] select(8, [7], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted) 
     92[pid 23967] --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- 
     93[pid 23967] sigreturn()                 = ? (mask now []) 
     94[pid 23967] select(8, [7], NULL, NULL, NULL) = ? ERESTARTNOHAND (To be restarted) 
     95[pid 23967] --- SIGVTALRM (Virtual timer expired) @ 0 (0) --- 
     96[pid 23967] sigreturn()                 = ? (mask now []) 
     97[pid 23967] select(8, [7], NULL, NULL, NULL) = 1 (in [7]) 
     98[pid 23967] recv(7, "\7\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\200\0\0\0\244]\0\0\0\0\0\0\0\0\0\0"..., 116, 0) = 116 
     99}}}