digitalmars.D.learn - vibe.d is blocking threads
- RuZzz (43/43) Apr 27 2016 Code:
- yawniek (4/16) Apr 27 2016 you should use the built in concurrency primitives vibe.d offers.
- Nicholas Wilson (2/23) Apr 27 2016 You don't. vibe.d uses fibers (aka green threads).
- Marc =?UTF-8?B?U2Now7x0eg==?= (8/35) Apr 28 2016 That doesn't matter. Native threads should work just fine, I'm
Code:
import std.concurrency;
import core.thread;
//import vibe.http.client; // If uncommented this line,
the thread "worker" does not start
void worker() {
foreach (i; 0 .. 5) {
Thread.sleep(500.msecs);
writeln(i, " (worker)");
}
}
void main() {
spawn(&worker);
foreach (i; 0 .. 5) {
Thread.sleep(300.msecs);
writeln(i, " (main)");
}
writeln("main is done.");
}
How to launch threads with vibe.d? It doesn't work at both
compilers.
- Gentoo Linux 64
- DMD64 D Compiler v2.069.0 (dub dependency)
- DMD64 D Compiler v2.071.0
- dub-0.9.24 USE="dmd-2_069"
dub.json:
{
"name" : "axt-threads-json",
"description" : "A minimal D bundle.",
"targetType": "executable",
"targetPath": "bin",
"dependencies" : {
"vibe-d": "~>0.7.28",
},
"configurations": [
{
"name": "Debuger"
},
{
"name": "Release"
}
]
}
Apr 27 2016
On Wednesday, 27 April 2016 at 13:00:29 UTC, RuZzz wrote:
Code:
import std.concurrency;
import core.thread;
//import vibe.http.client; // If uncommented this
line, the thread "worker" does not start
void worker() {
foreach (i; 0 .. 5) {
Thread.sleep(500.msecs);
writeln(i, " (worker)");
}
}
[...]
you should use the built in concurrency primitives vibe.d offers.
especially runTask and runWorkerTask.
see the vibe.d examples and http://vibed.org/features
Apr 27 2016
On Wednesday, 27 April 2016 at 13:00:29 UTC, RuZzz wrote:
Code:
import std.concurrency;
import core.thread;
//import vibe.http.client; // If uncommented this
line, the thread "worker" does not start
void worker() {
foreach (i; 0 .. 5) {
Thread.sleep(500.msecs);
writeln(i, " (worker)");
}
}
void main() {
spawn(&worker);
foreach (i; 0 .. 5) {
Thread.sleep(300.msecs);
writeln(i, " (main)");
}
writeln("main is done.");
}
How to launch threads with vibe.d? It doesn't work at both
compilers.
You don't. vibe.d uses fibers (aka green threads).
Apr 27 2016
On Wednesday, 27 April 2016 at 23:30:10 UTC, Nicholas Wilson wrote:On Wednesday, 27 April 2016 at 13:00:29 UTC, RuZzz wrote:That doesn't matter. Native threads should work just fine, I'm using them without problems in a vibe.d app. Could it be that your main() function is never called at all? Try to insert a writeln() at the beginning. If so, this could be related to the "VibeDefaultMain" setting, see here: http://vibed.org/docs#custom-mainCode: import std.concurrency; import core.thread; //import vibe.http.client; // If uncommented this line, the thread "worker" does not start void worker() { foreach (i; 0 .. 5) { Thread.sleep(500.msecs); writeln(i, " (worker)"); } } void main() { spawn(&worker); foreach (i; 0 .. 5) { Thread.sleep(300.msecs); writeln(i, " (main)"); } writeln("main is done."); } How to launch threads with vibe.d? It doesn't work at both compilers.You don't. vibe.d uses fibers (aka green threads).
Apr 28 2016









yawniek <dlang srtnwz.com> 