Threads & fibers

Simen kjaeraas simen.kjaras at gmail.com
Sun Jan 30 12:22:58 PST 2011


Nrgyzer <nrgyzer at gmail.com> wrote:

> The result is: "true" which means that testInstance of type a is null -  
> but I
> already created a instance and if I write "writeln(testInstance is  
> null);" after
> Thread.yield(); in the main, it says "false" which means testInstance is  
> a valid
> instance of the class a. -> Why does threadFunc() says true, when  
> testInstance
> should be a valid instance of a?

The default storage in D is in TLS, that is, changes in one thread will
not be visible to others.

If instead you mark your class a as 'shared class a', it works the way
you'd expect it to.


> ... is there any chance to interrupt the Thread.sleep-command or to  
> suspend the
> thread? As I know, the join()-method does wait until the thread is  
> finished, but
> does not interrupt the sleep()-command.

I think the best way to do this would be using std.concurrency, and
passing it a message. Not sure, though.

-- 
Simen


More information about the Digitalmars-d-learn mailing list