Forums > Dev

Scheduling outlet calls from custom threads (or threads other than the main)

January 31, 2014 | 4:50 am

When in overdrive the execution mode of Max/MSP might involve up to 3 threads (audio, main, scheduler).
Therefore a clock will send any method to the scheduler thread, whereas a qelem will defer to the main/low priority thread.

1st Question:
browsing through the code of the simplethread.c example I see that to schedule outlet calls from custom threads the code employs qelems, which are set directly from custom threads without using a clock. I say "without using a clock" because once upon a time in this Tim Place said the following: (http://cycling74.com/forums/topic/qelem-questions/)

‘A qelem should only be set by the main thread or the scheduler thread. It should *not* be set directly from any other thread.
What we do in Max when we need to trigger a qelem from an arbitrary thread is to set a clock, and our clock function will then set a qelem. It’s an extra step, but this is how it is intended to function.’
So I am left a little confused…
Should we disregard the simplethread example because it is inaccurate?
Do we really need to use both clocks and qelems in sequence in order to schedule outlet calls at low priority?
It does seem a little weird to have to go thru the scheduler thread in order to go to the low-priority thread.
I am in need of some clarification on this point for sure…

2nd Question:
So far it has been advocated to use qelems in order to make outlet calls from custom threads, however I was told many times on the forum that if we want to make outlet calls from the Audio thread then we have to use clocks.

So, my second question would be:
may we use clocks to schedule outlet calls from custom threads if we intend those calls to be executed at high priority? Is it allowed or even wise to do so?
After all – if I think about it – I would probably want my outlet calls to be executed at high priority 99% of the times…

Please, some clarification would be highly appreciated.

Thank you.

- Luigi


Viewing 1 post (of 1 total)