Hello,
I would like to send a signal from c to ruby. So that ruby knows, that
there is some new data in c that can be fetched and extracted.
Currently I'm using ruby 1.8.5 on WindowsXP.
Are there any possibilities like Callbackfunction, Signals,
Interrupthandling ...
I've searched but found nothing for my needs.
Currently I have the following code. the Problem here is, that i have to
wait for the rubyscheduler until the ruby recvThread will be scheduled.
Although it could happen, that data will be lost, when there arrives new
data while ruby is currently "pop"-ing the array.
Have anybody got an idea?
Thanks for any tips.
Asterix
////////////////////////////////////////////////////////
// rubycode
require 'RubyDriver'
recvThread = Thread.new{
loop do
Thread.stop
while ( (msg = recvArray.pop) != nil) do
puts msg
end
end
}
RubyDriver::startReceiver(recvThread, recvArray)
////////////////////////////////////////////////////////
// c code
VALUE receiverThread, receiverArray;
void reciever(void* dummy) {
while(1) {
msg = recieveMessage(); // a C function wich
// returns if there is
// new data arrived
rb_ary_push(receiverArray, msg);
rb_thread_wakeup(receiverThread);
}
}
void startReceiver(VALUE thread, VALUE array) {
receiverThread = thread;
receiverArray = array;
hThread = (HANDLE)_beginthread( reciever, 0, NULL );
}
···
--
Posted via http://www.ruby-forum.com/.