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

BenKissBox's icon

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

AlexHarker's icon

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

AlexHarker's icon

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

All of these are covered by the SDK docs...

BenKissBox's icon

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

AlexHarker's icon

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

BenKissBox's icon

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

AlexHarker's icon

Ahhh. No problem.

Great that you've got it working!

A.

Timothy Place's icon

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