Are the Ruby bindings threadsafe?

Hi there,

just a quick question… I’ve got a GUI program doing some networking
stuff and want the GUI to react on what I get from my TCPSocket. To not
block the GUI when the server/connection is slow, I intend to extract
the networking stuff into a separate thread and then update the GUI
from that thread. So, can I for example do something like this:


@textview = Gtk::TextView.new
@textview.buffer.text = “Some initial text”

Thread.new do
sleep 5
@textview.buffer.text = “Some new text I got from somewhere else”
end

Continueing with other things in the main thread…


Is this possible or will I get segmentation faults or other unexpected
results? If not, are there any other possibilities to update widgets
from within another thread?

Valete,
Marvin


Blog: http://www.quintilianus.eu

ASCII-Ribbon-Kampagne () | ASCII Ribbon Campaign ()

For Ruiby, we use a Queue of bloc to be executed and a timer in
main window for pooling the queue and intance_eval the blocs received.

Main thread side:

$mainwindow=self
ici=self
GLib::Timeout.add(50) {
while $queue.size>0
mess= $queue.pop
ici.instance_eval(&mess) rescue log("#{$!} :\n #{
$!.backtrace[0…3].
join("\n “)}”)
end
true
}

socket thread side:

def gui_invoke(&blk)
$queue.push( blk )
end

Also, see :
http://verboselogging.com/2009/06/01/gtk-and-ruby-threading-issues

Am Tue, 17 Sep 2013 16:36:38 +0200
schrieb Regis d’Aubarede [email protected]:

For Ruiby, we use a Queue of bloc to be executed and a timer in
main window for pooling the queue and intance_eval the blocs received.

Also, see :
http://verboselogging.com/2009/06/01/gtk-and-ruby-threading-issues

Perfect! This was exactly what I was looking for. Thank you very much!

Valete,
Marvin


Blog: http://www.quintilianus.eu

ASCII-Ribbon-Kampagne () | ASCII Ribbon Campaign ()

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs