detecting POD types

2012-05-20 Thread japplegame
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?

Re: std.concurrency.send

2012-05-19 Thread japplegame
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

Re: std.concurrency.send

2012-05-19 Thread japplegame
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

std.concurrency.send

2012-05-19 Thread japplegame
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

shared associative array initialization

2012-05-13 Thread japplegame
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,

Re: shared attribute

2012-05-13 Thread japplegame
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

Re: shared attribute

2012-05-13 Thread japplegame
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

Re: shared attribute

2012-05-13 Thread japplegame
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

shared attribute

2012-05-13 Thread japplegame
Does shared attribute automatic synchronization or should I do it manually?

Re: std.concurrency and module constructors

2012-05-11 Thread japplegame
Thank you. Solution is: shared static this() { ... } or avoid any global things :)

std.concurrency and module constructors

2012-05-11 Thread japplegame
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