[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] concurrent conditions
playing around with the new sync / condition functionality,
I found that concurrent threads can pose problems as all
routines wait for the same /synced.
a possible solution might be to send a thread id with the \sync command.
if that poses problems, I've written a method for server which
makes it a bit easier to deal with:
schedSync { arg func;
syncTasks = syncTasks.add(func);
if(syncThread.isNil) {
syncThread = Routine.run {
var c; c = Condition.new;
while { syncTasks.notEmpty } {
syncTasks.removeAt(0).value(c) };
syncThread = nil;
};
};
}
// usage:
s.schedSync { arg c;
s.bootSync(c); // boot server. wait until booted before continuing.
SynthDef("maptest", { arg freq = 600;
Out.ar(0, SinOsc.ar(freq, 0, 0.2));
}, [0.1]).send(s);
s.sync(c); // wait until pending async operations are done.
s.sendMsg(\c_set, 12, 800); // set control bus
// new synth, map freq to control bus 12
s.sendMsg(\s_new, \maptest, 1001, 0, 0, \freq, \c12);
1.sleep; // sleep thread
s.sendMsg(\c_set, 12, 900);
1.sleep; // sleep thread
s.sendMsg(\c_set, 12, 700);
1.sleep; // sleep thread
};
_________________________________
shouldn't Routine.run return a routine? it returns nil now.
if, then:
*run { arg func, stackSize=512;
var res;
res = super.new(func, stackSize);
res.value;
^res;
}
--
.