hi list,
is it safe to set a clock using clock_set outside of the main loop thread? if not, is there a way to work around this?
tom
Hi, clock_set is supposed to be thread-safe (both in PD and xMax) - and it's one of the few.
In flext, it's used to implement a thread-safe message queue for sending messages to the objects' outlets.
best greetings, Thomas
----- Original Message ----- From: "Tom Schouten" doelie@zzz.kotnet.org To: pd-dev@iem.kug.ac.at Sent: Tuesday, December 03, 2002 7:57 PM Subject: [PD-dev] clocks & threads
hi list,
is it safe to set a clock using clock_set outside of the main loop thread? if not, is there a way to work around this?
tom
PD-dev mailing list PD-dev@iem.kug.ac.at http://iem.kug.ac.at/cgi-bin/mailman/listinfo/pd-dev
Hi all,
I don't think clock_set is thread safe in Pd... it manipulates a linked list (static) without locking other threads out of it....
cheers Miller
On Tue, Dec 03, 2002 at 08:09:49PM +0100, Thomas Grill wrote:
Hi, clock_set is supposed to be thread-safe (both in PD and xMax) - and it's one of the few.
In flext, it's used to implement a thread-safe message queue for sending messages to the objects' outlets.
best greetings, Thomas
----- Original Message ----- From: "Tom Schouten" doelie@zzz.kotnet.org To: pd-dev@iem.kug.ac.at Sent: Tuesday, December 03, 2002 7:57 PM Subject: [PD-dev] clocks & threads
hi list,
is it safe to set a clock using clock_set outside of the main loop thread? if not, is there a way to work around this?
tom
PD-dev mailing list PD-dev@iem.kug.ac.at http://iem.kug.ac.at/cgi-bin/mailman/listinfo/pd-dev
PD-dev mailing list PD-dev@iem.kug.ac.at http://iem.kug.ac.at/cgi-bin/mailman/listinfo/pd-dev
I don't think clock_set is thread safe in Pd... it manipulates a linked list (static) without locking other threads out of it....
I actually use clock_delay, but i guess that's just the same and i realized that i'm also using a mutex for it.
hi thomas,
i am wondering how you do this. did you patch pd to use a mutex in the clock routines also? because i can't see how it would be thread safe if you don't do that.
tom
Am Donnerstag, 05.12.02, um 04:15 Uhr (Europe/Vienna) schrieb Tom Schouten:
I don't think clock_set is thread safe in Pd... it manipulates a linked list (static) without locking other threads out of it....
I actually use clock_delay, but i guess that's just the same and i realized that i'm also using a mutex for it.
hi thomas,
i am wondering how you do this. did you patch pd to use a mutex in the clock routines also? because i can't see how it would be thread safe if you don't do that.
Hi Tom, you're right that there has to be a solution in PD itself. It did work for me only because of the fact that hardly anyone seemed to care about threads....
There has already been a discussion several month ago, but now seems to be the time we'll have to do something about it...
best greetings, Thomas
Thomas Grill schrieb:
you're right that there has to be a solution in PD itself. It did work for me only because of the fact that hardly anyone seemed to care about threads....
My solution after some (by that time) unexplainable 'voodoo crahses' with oggcast~ was to use clocks as a sort of callback function. I pass data between the main thrad of my external and it's child thread using a mutex. The output is realised by setting a clock (from the main thread!) that calls itselfe over and over again. In this function I then lock the mutex and check wether some data has changed and needs to be output.... (setting a clock with clock_delay(myclock, 0) from within the child thread crashed Pd (it sometimes worked for some hours but in the end it sooner or later crashed)). This is of course not very efficient and a possibility to set a clock _only_ when it is needed would make things much easier.
Olaf
My solution after some (by that time) unexplainable 'voodoo crahses' with oggcast~ was to use clocks as a sort of callback function. I pass data between the main thrad of my external and it's child thread using a mutex. The output is realised by setting a clock (from the main thread!) that calls itselfe over and over again. In this function I then lock the mutex and check wether some data has changed and needs to be output.... (setting a clock with clock_delay(myclock, 0) from within the child thread crashed Pd (it sometimes worked for some hours but in the end it sooner or later crashed)).
When oggcast crashes while it is running alone (with no other threaded externals around), this would mean that the main and child thread collide, wouldn't it? This should be solvable by a mutex inside your external.
Concerning thread-safe PD... what functions do we want to be thread-safe? For my part, i really only need clock_set, since all other issues are handled by flext.
greetings, Thomas
Concerning thread-safe PD... what functions do we want to be thread-safe? For my part, i really only need clock_set, since all other issues are handled by flext.
if outlet_thingy would be thread safe, that would be really nice, but i guess that is a bit too much to ask. :)
i can live with clock_set being thread safe. it would be nice to have a sort of synchronous communication:
* receive a message * pass some data to another thread (thread starts processing, main thread continues) * when thread is finished, it signals this using clock_set, meaning the next pd scheder run the data processed is available in the main thread again.
this seems to be all there is needed for simple load balancing tasks using threads.
tom
Thomas Grill schrieb:
When oggcast crashes while it is running alone (with no other threaded externals around), this would mean that the main and child thread collide, wouldn't it? This should be solvable by a mutex inside your external.
Hi Thomas,
well, I have a mutex inside it! And I couldn't really reproduce these crashes but removing the clock_delay() call from the child thread solved the problem. Now it runs for weeks without crashing. The function that is called by clock_delay() from the _main_ thread of course locks the mutex before doing anything else.... (I actually call the same function, just from the main thread instead).
Concerning thread-safe PD... what functions do we want to be thread-safe? For my part, i really only need clock_set, since all other issues are handled by flext.
Yes, I think that would be enough. And it would be very cool! ;-)
Olaf