Skip to content

Commit

Permalink
[project @ 2004-03-01 14:18:35 by simonmar]
Browse files Browse the repository at this point in the history
Threaded RTS improvements:

  - Make the main_threads list doubly linked.  Have threads
    remove themselves from this list when they complete, rather
    than searching for completed main threads each time around
    the scheduler loop.  This removes an O(n) loop from the
    scheduler, but adds some new constraints (basically completed
    threads must remain on the run queue until dealt with, including
    threads which have been killed by an async exception).

  - Add a pointer from the TSO to the StgMainThread struct, for
    main threads.  This avoids a number of places where we had
    to traverse the list of main threads to find the right one,
    including one place in the scheduler loop.  Adding a field to
    a TSO is cheap.

  - taskStart: we should be resetting the startingWorkerThread flag
    in here.  Not sure why we aren't; maybe this got lost at some point.

  - Use the BlockedOnCCall flags in the non-threaded RTS too.  Q: what
    should happen if a thread does a foreign call which re-enters the
    RTS, and then sends an async exception to the original thread?
    Answer: it should deadlock, which it does in the threaded RTS, and
    this commit makes it do so in the non-threaded RTS too (see
    testsuite/tests/concurrent/should_run/conc040.hs).
  • Loading branch information
simonmar committed Mar 1, 2004
1 parent 07e22b0 commit a20ec0c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 166 deletions.
21 changes: 10 additions & 11 deletions ghc/includes/TSO.h
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------------
* $Id: TSO.h,v 1.33 2003/11/12 17:27:05 sof Exp $
* $Id: TSO.h,v 1.34 2004/03/01 14:18:35 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
Expand Down Expand Up @@ -161,11 +161,9 @@ typedef enum {
, BlockedOnGA // blocked on a remote closure represented by a Global Address
, BlockedOnGA_NoSend // same as above but without sending a Fetch message
#endif
#if defined(RTS_SUPPORTS_THREADS)
, BlockedOnCCall
, BlockedOnCCall_NoUnblockExc // same as above but don't unblock async exceptions
// in resumeThread()
#endif
, BlockedOnCCall_NoUnblockExc // same as above but don't unblock
// async exceptions in resumeThread()
} StgTSOBlockReason;

#if defined(mingw32_TARGET_OS)
Expand Down Expand Up @@ -204,12 +202,13 @@ typedef struct StgTSO_ {
StgMutClosure * mut_link; /* TSO's are mutable of course! */
struct StgTSO_* global_link; /* Links all threads together */

StgTSOWhatNext what_next : 16;
StgTSOBlockReason why_blocked : 16;
StgTSOBlockInfo block_info;
struct StgTSO_* blocked_exceptions;
StgThreadID id;
int saved_errno;
StgTSOWhatNext what_next : 16;
StgTSOBlockReason why_blocked : 16;
StgTSOBlockInfo block_info;
struct StgTSO_* blocked_exceptions;
StgThreadID id;
int saved_errno;
struct StgMainThread_* main;

MAYBE_EMPTY_STRUCT(StgTSOTickyInfo,ticky)
MAYBE_EMPTY_STRUCT(StgTSOProfInfo,prof)
Expand Down
4 changes: 3 additions & 1 deletion ghc/rts/Exception.h
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------------
* $Id: Exception.h,v 1.7 2003/11/12 17:49:07 sof Exp $
* $Id: Exception.h,v 1.8 2004/03/01 14:18:35 simonmar Exp $
*
* (c) The GHC Team, 1998-2000
*
Expand Down Expand Up @@ -27,6 +27,8 @@ interruptible(StgTSO *t)
#endif
case BlockedOnDelay:
return 1;
// NB. Threaded blocked on foreign calls (BlockedOnCCall) are
// *not* interruptible. We can't send these threads an exception.
default:
return 0;
}
Expand Down

0 comments on commit a20ec0c

Please sign in to comment.