Multithreading and Loggers

Byron Heads byron.heads at gmail.com
Fri Jan 31 06:03:35 PST 2014


On Fri, 31 Jan 2014 13:48:07 +0000, Nicolas F. wrote:

> However, apparently the callback function is possibly called from a
> different thread which I have no control over, as I've had to painfully
> discover. My mainLogger static variable is useless, and everything falls
> apart. I'm not sure where this thread comes from, and maybe I'm just
> imagining things, but since I see no other way the variable could
> suddenly become null, I'm guessing that's the issue.
> 

Are you using a lib like GLFW or GLW?  A lot of these libraries create 
threads for you. That maybe where this thread is coming from.

When you set this call back are you able to supply user data with it?  
Good callback API's should do this.  If so you can supply a logger 
instance pointer that way.

You could also use a global logger factor/manager.  Checkout std.idioms 
[https://github.com/D-Programming-Language/phobos/pull/1294/files]

-Byron


More information about the Digitalmars-d mailing list