www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 645] New: Race condition in std.thread.Thread.pauseAll

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=645

           Summary: Race condition in std.thread.Thread.pauseAll
           Product: D
           Version: 0.176
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: kinaba is.s.u-tokyo.ac.jp


Line 334 and 335   phobos/std/thread.d

  > if (t && t !is tthis && t.state == TS.RUNNING)
  >   t.pause();

The thread t may change its state before t.pause() and
after t.state == TS.RUNNING. For example, it may finish running.
If that happens, an exception is thrown:

  > Error: Thread error: cannot pause

and thus the whole execution of pauseAll() fails.
But IMHO pauseAll should not fail.

The situation can be reproduced by the following code.

------------------------
// credit goes to http://f17.aaa.livedoor.jp/~labamba/?BugTrack%2F26
import std.thread;

class DoNothing : Thread // threads that does nothing
{
  int run() { return 0; }
}

class StartAndTerminateLoop : Thread
{        // infinitely starting and terminating threads
  int run()
  {
    for(;;) {Thread t=new DoNothing; t.start; t.wait;}
    return 0;
  }
}

void main()
{
  (new StartAndTerminateLoop).start;
  for(;;) { Thread.pauseAll; Thread.resumeAll; }
      // infinitely repeat pauseAll/resumeAll
      //   and eventually triggers the race hazard
}
------------------------

One way to solve this problem is providing a private
non-throwing pause() function and using it in pauseAll().


-- 
Dec 04 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=645


braddr puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED





Please see the patch attached to bug 318.  It should fix this bug as well.


-- 
Oct 27 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=645


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED





Fixed dmd 1.023 and 2.007


-- 
Nov 03 2007