How can I create a method being called by Max low priority thread ?

Aug 24, 2011 at 6:45am

How can I create a method being called by Max low priority thread ?

Hello all,
I am writing an external which uses basically two thread : the time critical thread (the “overdriven” one in Max), but it also needs to be called by the main thread (I make system calls, which can delay the processing a lot, and it is not possible to put it in the main thread).

For technical reasons on Mac platform, the functions I am talking about *must* be called by Max main thread.

I did not find in the doc and in the forum what I have to do to get called by Max main thread (I expect clocks and threads created by my externals to scheduled at high priority)

So, my question is quite simple : how can I create a method which is called by Max low priority thread?

Thanks by advance for your help

Benoit

#58601
Aug 24, 2011 at 7:23pm

you can use defer, defer_medium() or deferlow to make sure that something is executing in the main thread (according to whether you want these).

If you want the methods to be accessible to the user, and you don’t want to have to write a function to defer I think you can define your function so that it is always deferred, using a A_DEFER_LOW, which is like A_GIMME but will be deferred.

Alex

#210661
Aug 24, 2011 at 10:08pm

meant to say – according to which behaviour you want) in the first para above.

All of these are covered by the SDK docs…

#210662
Aug 25, 2011 at 5:28am

Hello Alex,

I saw defer_xxx functions, but I could not use them, since they need to be called by a high priority thread.
After reading your message and the SDK docs once again, I started to get the idea under it (all the externals I wrote up to now were using only dedicated threads for networking, or high priority thread for MIDI or audio processing)

I will experiment your suggestion about the deferlow with A_GIMME parameter today.

Thanks for the tip

Benoit

#210663
Aug 25, 2011 at 12:01pm

I’m not sure where you get the idea that the defer functions need to be called from the high-priority thread? You can call them from either max thread.

Alex

#210664
Aug 25, 2011 at 7:51pm

Oooops, I just noticed what I wrote. I meant to say “I thought I could not use them”… Do not ask me why I had this feeling about the deferred methods…

Your suggestion was correct : I just made a test with clock calling a method by defer_low, and it works perfectly.

Thank you for your help

Benoit

#210665
Aug 25, 2011 at 8:05pm

Ahhh. No problem.

Great that you’ve got it working!

A.

#210666
Aug 25, 2011 at 11:36pm

In addition to using defer_low() and friends, I’ll also put in a plug for using a qelem.

It will accomplish the same thing, but it should be considered as generally preferable because ownership of the event being pushed into the queue (and the mechanism pushing it) is clear.

Cheers,
Tim

#210667

You must be logged in to reply to this topic.