mvidner / ruby-dbus

A Ruby binding for DBus
GNU Lesser General Public License v2.1
170 stars 48 forks source link

Multithread in ruby-dbus #7

Open flagos opened 14 years ago

flagos commented 14 years ago

Hi,

We quite need for our project to use ruby-dbus multhreaded. This feature is not supported as reported in 20 - 21 -22. We are thinking about an implementation and we want to have an enlightened opinion before coding it.

The problem seems to be due to update_buffer function and IO.select. Update_buffer function doesn’t know from which does come the previous request and the first thread that take IO.select income takes the request. A way to solve it may be to dedicate a thread that wait IO.select and return the buffer to the according thread:

if message-type is METHOD_CALL or SIGNAL, return to main thread. if MESSAGE_RETURN, return to concerned thread. To do so, we need when sending a message to log in a hash (for example) the thread it cames from.

The thread will wait a Thread.stop and will be restarted from the dedicated one with a Thread.run

Do you agree with this implementation, do you see limitations from that ?

lschneiderbauer commented 14 years ago

Sorry to interrupt. I experienced some problems, when adding signal-callbacks after starting the dbus-main-loop. The added callbacks simply don't get called in this case. But this szenario is often required. For example, when communicating with Networkmanager (signal-callbacks for changed Wifi Accesspoints must be added on runtime).

Does your multithreading-implementation aim such a feature as well?

mvidner commented 14 years ago

Hi flagos,

hurray, thanks for offering the help with threads. The approach looks reasonable to me, however, I don't consider myself knowledgeable enough around concurrency and thread safety. I'll read up and ask around. As this deserves a broader discussion, why don't we continue on the mailing list? https://lists.luon.net/listinfo/ruby-dbus-devel

Please go ahead, but remember to include test cases. They don't have to be perfect, just a sample of code that somehow fails with the current library. I am sending one test case in progress [to the mailing list]: it hangs after invoking the method about 2 times in each thread, I haven't looked yet where in code it gets stuck.

Martin

mvidner commented 11 years ago

Status: some stalled attempts to solve this, from Jaunary 2011, are in https://github.com/mvidner/ruby-dbus/tree/multithreading