Values and Threads


#1

I was under the impression that the default ValueSource used an AsyncUpdater, thus making it threadsafe. Maybe I misunderstood - the Listener report is async but the actual Value update isn’t, therefore it’s not usable across threads?

Anyone have tips on changing a Value from a thread?

Bruce


#2

I would use a thread queue…


#3

A VFLib piece? So I would call setValue and it would operate on the other thread? That would be the ticket… but I just realized that I will need to determine the state of other values, to decide what to do. Case in point being a ‘toggle’ operation, where I need to know the current value so I can decide whether to set off or on. So I will need to operate on the main thread (curses). I could get all clever passing the (in this case) Midi Message to a queue, but I think I may as well just get a Message thread lock.

Wait - the Midi callback thread isn’t the audio thread is it? Can I block that safely?

Edit: bugger, no I can’t. Back to the drawing board.

Bruce


#4

Seek, and thou shalt find.

MidiMessageCollector seems just the ticket - Jules did the hard work for me, as usual :slight_smile:


#5

Then you write this function:

void toggleValue (Value* pValue)
{
  pValue->setValue ((pValue->getValue() == 1) ? 0 : 1);
}

and call that in the thread queue:

m_queue.call (&toggleValue, &value);

#6

[quote=“TheVinn”][Then you write this function:

void toggleValue (Value* pValue)
{
  pValue->setValue ((pValue->getValue() == 1) ? 0 : 1);
}

and call that in the thread queue:

m_queue.call (&toggleValue, &value); [/quote]

Oh, that’s clever. OK. I did the quickie now (timer and midicollector), but I’ll use that next time.