Multithreading in D confuses me more and more.
import std.concurrency;
import std.stdio;
shared Tid tid;
void main() {
send(cast(Tid)tid, "Hello, World");
}
void worker() {
writeln(receiveOnly!string);
}
shared static this() {
tid = cast(shared)spawn(&worker);
}
I hate these explicit cast
On Saturday, 19 May 2012 at 13:26:20 UTC, japplegame wrote:
Multithreading in D confuses me more and more.
import std.concurrency;
import std.stdio;
shared Tid tid;
void main() {
send(cast(Tid)tid, "Hello, World");
}
void worker() {
writeln(receiveOnly!string);
}
shared static this() {
ti
You don't need to mark Tids as shared.
Okay. I'm writting logger. Logger is global object and it is
running in its own separate thread (for example, writting logs to
remote database).
My application has several threads and all of them want to log
something. How to share this global logger between
On Saturday, 19 May 2012 at 21:13:14 UTC, japplegame wrote:
You don't need to mark Tids as shared.
Okay. I'm writting logger. Logger is global object and it is
running in its own separate thread (for example, writting logs
to
remote database).
My application has several threads and all of them
public:
void startLogger(LogConstructorArgs args) {
loggerTid = spawn(&loggerThread, args);
}
void log(string msg, OtherOptions oo) {
loggerTid.send(LogMsg(msg, oo));
}
void stopLogger() {
loggerTid.send(QuitMsg());
}
private:
Tid loggerTid;
struct LogMsg {
string msg;
Othe
On Sunday, 20 May 2012 at 04:09:50 UTC, japplegame wrote:
public:
void startLogger(LogConstructorArgs args) {
loggerTid = spawn(&loggerThread, args);
}
void log(string msg, OtherOptions oo) {
loggerTid.send(LogMsg(msg, oo));
}
void stopLogger() {
loggerTid.send(QuitMsg());
}
private:
On May 19, 2012, at 2:13 PM, japplegame wrote:
>> You don't need to mark Tids as shared.
> Okay. I'm writting logger. Logger is global object and it is
> running in its own separate thread (for example, writting logs to
> remote database).
> My application has several threads and all of them want
This program works fine:
import std.concurrency;
struct A {
string a,b;
}
void main () {
immutable A a = immutable A( "blah" );
send( thisTid, a );
}
But if change struct A declaration to:
struct A {
string a,b,c;
}
I get this error during compilation:
/opt/dmd2/linux/bin64/../../src
On 08/07/2015 03:24 PM, Marek Janukowicz wrote:> This program works fine:
>
> import std.concurrency;
>
> struct A {
>string a,b;
> }
>
> void main () {
>immutable A a = immutable A( "blah" );
>send( thisTid, a );
> }
>
> But if change struct A declaration to:
>
> struct A {
>strin