Threads & fibers

Nrgyzer nrgyzer at
Sun Jan 30 12:10:31 PST 2011

Hey guys,

I already posted a thread in the wrong section (digitalmars.D instead of
digitalmars.D.learn) - sorry for that. I'm looking for a solution to suspend/
interrupt threads which are sleeping.

In the last few minutes I figured out some things I didn't understand exactly. I
tested thread and fibers from the core.thread-package.

My first test-code is the following:

import std.stdio;
import core.thread;

a testInstance;

class a {

	void writeTest() {




void main(string[] args) {

	testInstance = new a();

	Thread t = new Thread(&threadFunc);

	Thread.yield(); // give the thread a chance to call threadFunc()


void threadFunc() {

	writeln(testInstance is null);


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?

Next question: When I extend my threadFunc()... like the following:

void threadFunc() {

	writeln(testInstance is null);


... 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 hope anyone can help and know how I can do this all.

... sorry for double posting in digitalmars.d!

Thanks in advance!

More information about the Digitalmars-d-learn mailing list