[Issue 1828] New: Several Thread Issues
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 11 17:04:03 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1828
Summary: Several Thread Issues
Product: D
Version: 2.010
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: patch
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: kinaba at is.s.u-tokyo.ac.jp
// Credit goes to http://pc11.2ch.net/test/read.cgi/tech/1202623572/30-35n
There are several problems in std.thread.
Please find attached the patch to fix all of them.
1. Thread.start
> state = TS.RUNNING;
> hdl = _beginthreadex(null, cast(uint)stacksize, &threadstart, cast(void*)this, 0, &id);
If context-switch occurs between these two lines,
thread which acutually is not running is treated as TS.RUNNING.
This causes problems, for example in pauseAll().
So these lines should be property synchronized.
> if (hdl == cast(thread_hdl)0)
When _beginthreadex fails and this branch is taken,
the variable nthread should be decremented.
2. std.wait timeouts
When a call to wait() timeouts (not fails),
> dw = WaitForSingleObject(hdl, 0xFFFFFFFF);
> state = TS.FINISHED;
the current implemetation treats it as it fails.
But in this case, the thread is indeed still alive and may wake up again
just after the "state = TS.FINISHED" statement. If that happens,
pauseAll() do not stop the thread (because it's TS.FINISHED) and
multiple threads may unintendedly run parallel.
This IS a problem for std.gc, which is relying on the assumption that
pauseAll() stops all but gc threads.
3. Priority
It is convenient if one can set the NORMAL thread priority.
--
More information about the Digitalmars-d-bugs
mailing list