Signal and slot trouble

div0 div0 at sourceforge.net
Sun Nov 21 01:40:49 PST 2010


This is just a random stab in the dark, but my guess is that std.signals 
hasn't been updated since the changes that make global vars live in TLS.

Try

__gshared SignalForwarder sigWinchSignal;
__gshared SignalForwarder sigAlrmSignal;


On 21/11/2010 08:05, Peter Federighi wrote:
> So, I've been trying to come up with an nice way of dealing with POSIX/Linux
> signals when I discovered std.signals.  It looked cool, and while it doesn't
> provide exactly what I want to do (since I have to use global functions in
> order to use sigaction), it's nice enough.  So here's a simplified form of
> what I'm trying to do (it doesn't actually do anything).  It compiles fine,
> but segfaults on the connect call.
>
> Any ideas?
> Thank you,
> - Peter
>
> import std.signals;
> import std.stdio;
>
> class SignalForwarder
>      {
>      mixin Signal!(int);
>      }
>
> SignalForwarder sigWinchSignal;	// Window size change signal
> SignalForwarder sigAlrmSignal;	// Timer alarm signal
>
> void main()
>      {
>      SigWinchHandler winch;
>      SigAlrmHandler alrm;
>
>      // put sigaction code here
>
>      sigWinchSignal.connect(&winch.handler);
>      sigAlrmSignal.connect(&alrm.handler);
>
>      // do something here
>      }
>
> // the functions that get called via sigaction
> void sigWinch(int signal)
>      {
>      sigWinchSignal.emit(signal);
>      }
>
> void sigAlrm(int signal)
>      {
>      sigAlrmSignal.emit(signal);
>      }
>
> // perhaps one of many functions I want called when a signal is raised
> class SigWinchHandler
>      {
>      void handler(int signal)
> 	{
> 	writeln("WINCH");
> 	}
>      }
>
> class SigAlrmHandler
>      {
>      void handler(int signal)
> 	{
> 	writeln("ALRM");
> 	}
>      }


-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list