Parallelism
Robbin via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 24 13:30:26 PDT 2015
I am writing a daemon that parses an ini file and goes about its
business. In C++ I create a thread that does an inotify on the
ini file and when it changes, it locks the associative array that
contains the parsed ini file, reparses it and then does an unlock
and goes back to waiting for the ini file to change again. If
the daemon needs ini data, it too participates in the lock and
will wait until the new ini data is ready.
Problem 1 is defining the thread variable as a member of my ini
class. Since I have to use the auto t = thread(&parser), I can't
figure out what type to make t in the class. auto is no good
without a rhs to give it meaning. I tried Task and task, but got
compiler complaints.
Problem 2 is the std.parallelism.Task is a struct and if I read
correctly, structs are built on the stack and not the heap. Once
I've exited the function that creates the thread, does it go out
of scope? I want the thread variable to be a member of a class,
so it will live on but maybe the thread will become extinct even
if the variable lives on. If I could get it to compile, I could
answer this question with experimentation.
Problem 3 is there is some mention of memory in a parallelism
task being for exclusive use by the task. My intent is to
lock/unlock the Associative Array while it is being accessed.
And that AA is a member of a class. Would operating on a shared
class member break the paradigm of std.parallelism?
In C++ I used the thread() method and so long as the member
function it started was static, I got along pretty well. Is this
the wrong approach?
RC
More information about the Digitalmars-d
mailing list