• SoftwarePure Data
  • Parallel second task beside perform task with lower priority in pure data

Hi,
I was wondering if it is possible to run a second task beside the perform task with lower priority in a pure data external.
My problem is that I have to find an index in a database which is very time consuming. The bigger the database is, the longer it takes, so at some point it cannot finish the search within the time window of the perform task and I have to choose a bigger buffer size. Therefore I would like to run the index search in a second task and the perform task works with the old index until the second task found a new one, even if it takes four or more cycles of the perform task.
Any ideas how this can be done?
Thanks in advance, Klemenz!

edit: Actually I think the index search is finished within the perform task cycle, but it causes a lot of CPU load.
But still if the index search would run in a second task I would save a lot of CPU load and I could use bigger
databases.

    klemenz I was wondering if it is possible to run a second task beside the perform task with lower priority in a pure data external.

    You could write a Pd external that instantiates its own thread, where this search takes place. Then you'd need a thread-safe way of passing the result to the audio thread (e.g.: use a lock-free ringbuffer such as this one). If you want a solution that is Bela-specific, and without creating a Pd external, you can do that by using a custom render file for your Pd project on Bela, as explained here.

    4 days later

    Thanks a lot! So I programmed two externals now. The first is searching the index and output the HRTF pair as lists on two outlets. Now I am not sure about the ringbuffer. I am having trouble to read in the lists. Is it possible to read the whole list into an array at once and write it directly into memory or is their a method necessary to copy the list from the inlet into an array. Code snippets would be appreciated. Thanks for your help, Klemenz!

    Is that a pd list? Not sure how that is stored in memory. Through the ringbuffer you can only send "flattened" data (i.e.: a contiguous set of bytes). You may not want to send Pd messages across the ringbuffer (although it's probably doable) and instead send some simpler data and assemble the Pd message from the simpler data within the audio thread.