From: Francis Cianfrocca Date: 2006-08-01T21:54:56+09:00 Subject: Re: Signaling Ruby from C/C++ Does this actually work??? Windows doesn't have signals, so maybe you've gotten lucky with whatever mechanism Ruby uses to simulate signals on Windows. I would doubt this solution works reliably on Unix or Linux, because a signal is delivered to the whole process, and in general you can't predict which thread will handle it. (Unless there's something magic about rb_f_kill that I don't know about.) Have you tried sending data to a file descriptor in the native thread, and selecting the descriptor for readable in the Ruby thread? I know this works, and there have been several threads about this approach on this board in the last few months. On 8/1/06, Asterix Gallier wrote: > now I've tried another solution. I'm sending a signal to the Rubyprocess > and catch this signal with trap. > > - Is this solution threadsafe? I didn't know in which way ruby handles > the signal exactly. > - Could it be, that some Signals are getting lost because of the > Handling Routine is already active? > > //////////////////////////////////////////////////////// > // rubycode > > require 'RubyDriver' > > Signal.trap("TERM") do > puts recvArray.pop.to_s > end > > RubyDriver::startReceiver(recvThread, recvArray) > > //////////////////////////////////////////////////////// > // c code > > void reciever(void* dummy) { > > VALUE msgsignal[2]; > msgsignal[0] = rb_str_new2("TERM"); > msgsignal[1] = ProcessId; > > while(1) { > msg = recieveMessage(); // a C function wich > // returns if there is > // new data arrived > rb_ary_push(receiverArray, msg); > rb_f_kill(2, msgsignal); > } > } > > > void startReceiver(VALUE pId, VALUE array) { > processId = pId; > receiverArray = array; > > hThread = (HANDLE)_beginthread( reciever, 0, NULL ); > } > > > -- > Posted via http://www.ruby-forum.com/. > >