Signals & Slots
Lutger
lutger.blijdestijn at gmail.com
Mon Nov 5 07:12:44 PST 2007
Lars Ivar Igesund wrote:
> It would be nice to have some actual
> evidence in this matter (either way, although I understand that complete
> thread safety may be impossible to prove for an efficient solution).
>
The following hack resulted in a deadlock on my machine. I also found
some access violations, this is perhaps a bug in sslot. A similar
program for std.signals also gave deadlocks.
Well, this thread has reminded me I should remove the pretense that is
multithreaded signals in sslot :)
import std.stdio;
import std.thread;
import std.gc;
import sslot = sslot.signal;
class Observer
{
void watch(char[] msg, int i)
{
writefln("Observed msg '%s' and value %s", msg, i);
}
~this()
{
writef("died...");
}
}
sslot.SignalMT!(void, char[], int) signal;
class FooThread : Thread
{
int run()
{
while(true)
{
Observer o = new Observer;
signal ~= &o.watch;
signal("message", 2);
o = null;
std.gc.fullCollect();
}
return 0;
}
}
void main()
{
std.gc.minimize();
signal = new sslot.SignalMT!(void, char[], int);
auto thread = new FooThread;
thread.start();
while(true)
signal("message", 1);
}
More information about the Digitalmars-d
mailing list