Releasing a buffer in min-devkit


    Jun 04 2019 | 10:14 pm
    Hi all,
    I have an external that accesses a buffer and returns all the values as a list.
    I understand that I lock the buffer at the start of my process using the buffer_lock template, but do I need to unlock the buffer afterwards? What are best practices for thread safety in a message that deals with a buffer in any way?
    Sample code of said buffer access is provided :)
        message<> bang {this, "bang", "Get values from buffer as a list.",         MIN_FUNCTION {             buffer_lock<> b(buffer); // Lock the buffer if (b.valid()) { // If the buffer is valid                 number frames = b.frame_count();                 atoms values(frames); // auto chan = std::min<size_t>(channel - 1, b.channel_count()); // Channel // Loop over the samples for (auto i = 0; i < frames; i++) { values[i] = b.lookup(i, 0); } list_out.send(values); } return {}; } };

    • Jul 10 2019 | 6:44 pm
      Hi James,
      When the buffer_lock<> goes out of scope (at the end of the MIN_FUNCTION) then it will release the lock automatically. This is one of the joys of Min!
      :-)