I write function template that should works only with POD types
(i.e. base types, structures, enums etc.). Is there something
like C++11 std::is_pod
(http://en.cppreference.com/w/cpp/types/is_pod) template?
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
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
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
I have no idea how to simple initialize shared associative array.
This code compiled but causing access violation when running.
shared uint[char] arr;
shared static this() {
// next expression seems wrong, because
// arr is process related and ['a':1, 'b':2] is thread related
// probably,
Thank you very much.
I already readed this excellent article.
Unfortunately, sometimes we need things that should be global and
shared between threads.
As far as I understand it is desirable to avoid casting to/from
shared.
It will be better to use something like this
shared char[] s;
shared stat
Very intresting. Next question. :)
Lets consider this example.
import core.thread;
import std.stdio;
shared char[] s;
char[] l = "shared text".dup;
void main() {
Thread worker = new Thread(&workerFunc);
worker.start();
Thread.sleep(dur!"seconds"(5)); // after this point worker
thread and it
Thanks.
Another question.
This doesn't compile:
shared char[] s = "shared text".dup;
with error:
cannot implicitly convert expression ("shared text") of type
char[] to shared(char[])
Why do I need to write this?
shared char[] s = cast(shared)"shared text".dup;
What is the meaning of this cas
Does shared attribute automatic synchronization or should I do it
manually?
Thank you.
Solution is:
shared static this() {
...
}
or avoid any global things :)
OS: Windows 7 64bit
Compiler: DMD32 D Compiler v2.059
Using spawn in module constructor causes very strange behavior.
import std.concurrency;
import std.stdio;
void main() {
}
void worker() {
receiveOnly!OwnerTerminated;
}
static this() {
writeln("module constructor");
spawn(&worker);
}
st
11 matches
Mail list logo