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

    Aug 24 2011 | 6:45 am
    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

    • Aug 24 2011 | 7:23 pm
      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.
    • Aug 24 2011 | 10:08 pm
      meant to say - according to which behaviour you want) in the first para above.
      All of these are covered by the SDK docs...
    • Aug 25 2011 | 5:28 am
      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
    • Aug 25 2011 | 12:01 pm
      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.
    • Aug 25 2011 | 7:51 pm
      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
    • Aug 25 2011 | 8:05 pm
      Ahhh. No problem.
      Great that you've got it working!
    • Aug 25 2011 | 11:36 pm
      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