From: Adam Bukowski Date: 2011-12-05T19:23:19+09:00 Subject: C module calling ruby code cause cfp consistency error Hi everyone, I need some help with joining C code with Ruby. My target is to use some system libraries to get active window title and write rest in ruby. I've written some module in C that uses wnck(on linux) to get window title. There must be some event loop which I run in different thread. When event window-changed occurs i want to call ruby method, to report window title. I've used some kind of observer pattern here, so ruby registers handler method in C module, and do something else. When there is no handler function call in C code - everything is great, but it makes no sense. Problem is that when I call ruby handler from different thread it causes cfp consistency error and rest of code in ruby file isn't working properly. It hangs waiting for window-change. When window is changed then it goes to next instruction. I've tried not to use native thread and call this blocking wnck's loop in ruby's Thread.new, but it hangs totally then. I've stuck. Ruby code is here, rest in attachments. Please give me support and some comments about handling cross threads calls. Thanks in advance, Adam require 'ActiveWindow' include ActiveWindow class TitleHandler def initialize @mutex = Mutex.new end def handle(title = '', wclass = '') @mutex.synchronize { print title + " - " + wclass + "\n" } end end handler = TitleHandler.new ActiveWindow.register_handler(handler, "handle") ActiveWindow.start_loop puts "wait..." sleep 1 puts "1" sleep 1 puts "2" sleep 1 puts "3" ActiveWindow.stop_loop puts "end" Attachments: http://www.ruby-forum.com/attachment/6812/ActiveWindow.c http://www.ruby-forum.com/attachment/6813/extconf.rb -- Posted via http://www.ruby-forum.com/.