digitalmars.D - Threads
- DF (21/21) Nov 19 2008 /**
- Spacen Jasset (3/30) Nov 19 2008 Not quite sure, but you could try derived.wait() in main to wait for the...
- DF (2/33) Nov 19 2008 It won't help. And method wait() is hidden. I'm using D 2.0.
- Sean Kelly (22/55) Nov 19 2008 If you're using D 2.0 then that shouldn't even compile. In fact,
- DF (3/67) Nov 19 2008 That's what I get when I try to compile the code you've posted.
- Jarrett Billingsley (4/71) Nov 19 2008 You're probably using an older compiler. std.thread has recently
- Robert Jacques (6/10) Nov 19 2008 The main thread is exiting before the derived thread runs. This works
- DF (2/14) Nov 19 2008 You'll get "Error: hidden method called for Test.DerivedThread" if try t...
- Robert Jacques (3/18) Nov 19 2008 This worked on my setup (D 1.035 + Phobos + Windows + Release), which
- DF (23/50) Nov 19 2008 The code above should be changed to:
- DF (2/61) Nov 19 2008 P.S. I'm using Digital Mars D Compiler v2.014
/** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?
Nov 19 2008
DF wrote:/** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?Not quite sure, but you could try derived.wait() in main to wait for the thread to finish.
Nov 19 2008
Spacen Jasset Wrote:DF wrote:It won't help. And method wait() is hidden. I'm using D 2.0./** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?Not quite sure, but you could try derived.wait() in main to wait for the thread to finish.
Nov 19 2008
DF wrote:Spacen Jasset Wrote:If you're using D 2.0 then that shouldn't even compile. In fact, std.thread doesn't exist any longer. Try: module Test; import core.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private: void run() { writefln( "Derived thread running." ); } } void main() { Thread derived = new DerivedThread(); derived.start(); } Note that if you set "Thread.isDaemon = true" then you will need to join() the thread to wait for it to complete before the app exits. SeanDF wrote:It won't help. And method wait() is hidden. I'm using D 2.0./** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?Not quite sure, but you could try derived.wait() in main to wait for the thread to finish.
Nov 19 2008
Sean Kelly Wrote:DF wrote:That's what I get when I try to compile the code you've posted. module thread cannot read file 'core\thread.d'Spacen Jasset Wrote:If you're using D 2.0 then that shouldn't even compile. In fact, std.thread doesn't exist any longer. Try: module Test; import core.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private: void run() { writefln( "Derived thread running." ); } } void main() { Thread derived = new DerivedThread(); derived.start(); } Note that if you set "Thread.isDaemon = true" then you will need to join() the thread to wait for it to complete before the app exits. SeanDF wrote:It won't help. And method wait() is hidden. I'm using D 2.0./** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?Not quite sure, but you could try derived.wait() in main to wait for the thread to finish.
Nov 19 2008
On Wed, Nov 19, 2008 at 2:53 PM, DF <deefriend ymail.com> wrote:Sean Kelly Wrote:You're probably using an older compiler. std.thread has recently become core.thread. Just change it to std.thread, or update your compiler.DF wrote:That's what I get when I try to compile the code you've posted. module thread cannot read file 'core\thread.d'Spacen Jasset Wrote:If you're using D 2.0 then that shouldn't even compile. In fact, std.thread doesn't exist any longer. Try: module Test; import core.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private: void run() { writefln( "Derived thread running." ); } } void main() { Thread derived = new DerivedThread(); derived.start(); } Note that if you set "Thread.isDaemon = true" then you will need to join() the thread to wait for it to complete before the app exits. SeanDF wrote:It won't help. And method wait() is hidden. I'm using D 2.0./** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?Not quite sure, but you could try derived.wait() in main to wait for the thread to finish.
Nov 19 2008
On Wed, 19 Nov 2008 13:26:32 -0500, DF <deefriend ymail.com> wrote:void main() { Thread derived = new DerivedThread(); derived.start(); }The main thread is exiting before the derived thread runs. This works correctly: Thread derived = new DerivedThread(); derived.start(); derived.wait;
Nov 19 2008
Robert Jacques Wrote:On Wed, 19 Nov 2008 13:26:32 -0500, DF <deefriend ymail.com> wrote:You'll get "Error: hidden method called for Test.DerivedThread" if try to use derived.wait.void main() { Thread derived = new DerivedThread(); derived.start(); }The main thread is exiting before the derived thread runs. This works correctly: Thread derived = new DerivedThread(); derived.start(); derived.wait;
Nov 19 2008
On Wed, 19 Nov 2008 13:33:26 -0500, DF <deefriend ymail.com> wrote:Robert Jacques Wrote:This worked on my setup (D 1.035 + Phobos + Windows + Release), which version are you using?On Wed, 19 Nov 2008 13:26:32 -0500, DF <deefriend ymail.com> wrote:You'll get "Error: hidden method called for Test.DerivedThread" if try to use derived.wait.void main() { Thread derived = new DerivedThread(); derived.start(); }The main thread is exiting before the derived thread runs. This works correctly: Thread derived = new DerivedThread(); derived.start(); derived.wait;
Nov 19 2008
DF Wrote:/** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?The code above should be changed to: /** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); derived.wait(); } Now it works thanks.
Nov 19 2008
DF Wrote:DF Wrote:P.S. I'm using Digital Mars D Compiler v2.014/** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } private : int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); } This code makes no output. Why?The code above should be changed to: /** * Testing. */ module Test; import std.thread; import std.stdio; class DerivedThread : Thread { this() { super(&run); } int run() { writefln("Derived thread running.\n" ); return 0; } } void main() { Thread derived = new DerivedThread(); derived.start(); derived.wait(); } Now it works thanks.
Nov 19 2008