November 19, 2008 Re: Threads | ||||
|---|---|---|---|---|
| ||||
Posted in reply to DF | On Wed, Nov 19, 2008 at 2:53 PM, DF <deefriend@ymail.com> wrote:
> Sean Kelly Wrote:
>
>> DF wrote:
>> > Spacen Jasset Wrote:
>> >
>> >> 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.
>> > It won't help. And method wait() is hidden. I'm using D 2.0.
>>
>> 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.
>>
>>
>> Sean
>
> That's what I get when I try to compile the code you've posted.
>
> module thread cannot read file 'core\thread.d'
You're probably using an older compiler. std.thread has recently become core.thread. Just change it to std.thread, or update your compiler.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply