<div dir="ltr">Have you checked out std.parallelism and std.concurrency?</div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-16 9:57 GMT+02:00 aki via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I can't resolve the compile errors:<br>
<br>
import core.thread;<br>
class DerivedThread : Thread {<br>
int count = 0;<br>
this() {<br>
super(&run);<br>
}<br>
private void run() {<br>
inc(); //testThread.d(8): Error: shared method testThread.DerivedThread.inc is not callable using a non-shared object<br>
}<br>
synchronized void inc() {<br>
++count; //testThread.d(11): Deprecation: read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!"+="(this.count, 1) instead.<br>
}<br>
}<br>
void main() {<br>
auto thr = new DerivedThread();<br>
thr.start();<br>
thr.inc(); //testThread.d(17): Error: shared method testThread.DerivedThread.inc is not callable using a non-shared object<br>
thr.join();<br>
}<br>
<br>
<br>
1. Should I declare thr as shared? But<br>
auto thr = new shared DerivedThread();<br>
does not resolve it.<br>
<br>
2. Why "++count" cause an error? I think it is safe because<br>
it is marked as synchronized. If it is forced to use atomicOp<br>
all the time, it's painful.<br>
<br>
3. Are there any tutorials about using Thread class?<span class="HOEnZb"><font color="#888888"><br>
<br>
Aki.<br>
<br>
</font></span></blockquote></div><br></div>