Here's how I wound up doing it. It still has the same trouble but I think I save resources by using locks.
Note that I live in C now and do evil pointer sharing. So multiple threads have the signal object. Each thread seems to take a full trip through the queue before they each see the signal. Maybe there's room for improvement. But the end result is pretty clean...
Code: Select all
unsigned int signal = 0;
void thread1()
{
...
signal = xcore_createsignal()
...
// Tell the other threads to RUN!
xcore_signal(signal);
}
void thread2()
{
...
// Wait for mommy to say it's safe.
xcore_waitsignal(signal)
...
}
void thread3()
{
...
// Wait for mommy to say it's safe.
xcore_waitsignal(signal)
...
}
Code: Select all
# Creates a signal
xcore_createsignal:
entsp 0x2
stw r1, sp[0x01]
getr r0, 0x05
in r1, res[r0]
ldw r1, sp[0x01]
retsp 0x02
# Signal the signal. Releases waiting threads!
xcore_signal:
entsp 0x2
stw r1, sp[0x01]
out res[r0],r1
in r1, res[r0]
ldw r1, sp[0x01]
retsp 0x02
# Wait on a signal. Other threads call this to block until signaled.
xcore_waitsignal:
entsp 0x2
stw r1, sp[0x01]
in r1, res[r0]
out res[r0],r1
ldw r1, sp[0x01]
retsp 0x02