digitalmars.D.learn - d threads primer
- prefetch (19/19) Aug 15 2005 i would've searched for this, but the 'newsguy' news service doesnt seem...
- Ben Hinkle (12/37) Aug 15 2005 you probably want
- prefetch (5/47) Aug 15 2005 ben, thanks for the reply. very helpful.
- prefetch (5/58) Aug 15 2005 oops - i spoke too soon. robermuench's code doesn't compile (i'm workin...
- Ben Hinkle (15/21) Aug 15 2005 Did you try something like this?
- prefetch (3/25) Aug 15 2005 thanks ben. that works. ;-)
i would've searched for this, but the 'newsguy' news service doesnt seem to have a search function. bleh. can anyone post a link to a "d threads primer"? i'm having trouble understanding what the thread methed 'run' wants from me. i'm a c coder, and i understand function pointers, but..well, here is a code snippet: void myfunc() { printf("hi\n"); } Thread mythread; mythread.run(&myfunc); thread.d(8): function std.thread.Thread.run () does not match argument types (void(*)()) thread.d(8): Error: expected 0 arguments, not 1 but what gives? the phobos docs say: int run(void* p); Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg. The return value is the thread exit code, which is normally 0. anyway, am i being lame, or is it d?
Aug 15 2005
"prefetch" <prefetch_member pathlink.com> wrote in message news:ddqno7$1ebq$1 digitaldaemon.com...i would've searched for this, but the 'newsguy' news service doesnt seem to have a search function. bleh. can anyone post a link to a "d threads primer"? i'm having trouble understanding what the thread methed 'run' wants from me. i'm a c coder, and i understand function pointers, but..well, here is a code snippet: void myfunc() { printf("hi\n"); } Thread mythread; mythread.run(&myfunc); thread.d(8): function std.thread.Thread.run () does not match argument types (void(*)()) thread.d(8): Error: expected 0 arguments, not 1you probably want Thread mythread = new Thread(&myfunc); mythread.start(); Four points to notice: 1) you need to 'new' your Thread object 2) don't call run() but instead pass the worker delegate to the Thread constructor 3) the new thread won't actually start until you call "start". 4) the phobos doc for the Thread constructors is wierd. I can't figure out what it's trying to say :-Pbut what gives? the phobos docs say: int run(void* p); Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg. The return value is the thread exit code, which is normally 0. anyway, am i being lame, or is it d?
Aug 15 2005
ben, thanks for the reply. very helpful. also, i managed to find this quick primer for future reference: http://robertmuench.de/notes/d/ cheers. In article <ddqotb$1fb6$1 digitaldaemon.com>, Ben Hinkle says..."prefetch" <prefetch_member pathlink.com> wrote in message news:ddqno7$1ebq$1 digitaldaemon.com...i would've searched for this, but the 'newsguy' news service doesnt seem to have a search function. bleh. can anyone post a link to a "d threads primer"? i'm having trouble understanding what the thread methed 'run' wants from me. i'm a c coder, and i understand function pointers, but..well, here is a code snippet: void myfunc() { printf("hi\n"); } Thread mythread; mythread.run(&myfunc); thread.d(8): function std.thread.Thread.run () does not match argument types (void(*)()) thread.d(8): Error: expected 0 arguments, not 1you probably want Thread mythread = new Thread(&myfunc); mythread.start(); Four points to notice: 1) you need to 'new' your Thread object 2) don't call run() but instead pass the worker delegate to the Thread constructor 3) the new thread won't actually start until you call "start". 4) the phobos doc for the Thread constructors is wierd. I can't figure out what it's trying to say :-Pbut what gives? the phobos docs say: int run(void* p); Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg. The return value is the thread exit code, which is normally 0. anyway, am i being lame, or is it d?
Aug 15 2005
oops - i spoke too soon. robermuench's code doesn't compile (i'm working the bugs out now) and also, ben - your suggestion doesn't seem to work out (though it makes more sense than what i was doing..) could i trouble you to compile it and check? In article <ddqpup$1g5n$1 digitaldaemon.com>, prefetch says...ben, thanks for the reply. very helpful. also, i managed to find this quick primer for future reference: http://robertmuench.de/notes/d/ cheers. In article <ddqotb$1fb6$1 digitaldaemon.com>, Ben Hinkle says..."prefetch" <prefetch_member pathlink.com> wrote in message news:ddqno7$1ebq$1 digitaldaemon.com...i would've searched for this, but the 'newsguy' news service doesnt seem to have a search function. bleh. can anyone post a link to a "d threads primer"? i'm having trouble understanding what the thread methed 'run' wants from me. i'm a c coder, and i understand function pointers, but..well, here is a code snippet: void myfunc() { printf("hi\n"); } Thread mythread; mythread.run(&myfunc); thread.d(8): function std.thread.Thread.run () does not match argument types (void(*)()) thread.d(8): Error: expected 0 arguments, not 1you probably want Thread mythread = new Thread(&myfunc); mythread.start(); Four points to notice: 1) you need to 'new' your Thread object 2) don't call run() but instead pass the worker delegate to the Thread constructor 3) the new thread won't actually start until you call "start". 4) the phobos doc for the Thread constructors is wierd. I can't figure out what it's trying to say :-Pbut what gives? the phobos docs say: int run(void* p); Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg. The return value is the thread exit code, which is normally 0. anyway, am i being lame, or is it d?
Aug 15 2005
"prefetch" <prefetch_member pathlink.com> wrote in message news:ddqrj4$1hi1$1 digitaldaemon.com...oops - i spoke too soon. robermuench's code doesn't compile (i'm working the bugs out now) and also, ben - your suggestion doesn't seem to work out (though it makes more sense than what i was doing..) could i trouble you to compile it and check?Did you try something like this? import std.thread; int main() { int myfunc() { printf("hi\n"); return 0; // 0 means normal return } Thread mythread = new Thread(&myfunc); mythread.start(); for (int k = 0; k<100000; k++) Thread.yield(); // give the other thread a chance return 0; }
Aug 15 2005
thanks ben. that works. ;-) it'll help me get started. thanks again. In article <ddqtcd$1j77$1 digitaldaemon.com>, Ben Hinkle says..."prefetch" <prefetch_member pathlink.com> wrote in message news:ddqrj4$1hi1$1 digitaldaemon.com...oops - i spoke too soon. robermuench's code doesn't compile (i'm working the bugs out now) and also, ben - your suggestion doesn't seem to work out (though it makes more sense than what i was doing..) could i trouble you to compile it and check?Did you try something like this? import std.thread; int main() { int myfunc() { printf("hi\n"); return 0; // 0 means normal return } Thread mythread = new Thread(&myfunc); mythread.start(); for (int k = 0; k<100000; k++) Thread.yield(); // give the other thread a chance return 0; }
Aug 15 2005