[Git][ghc/ghc][wip/clear-block-info] rts: Clear block_info when unblocking
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Wed May 10 19:29:16 UTC 2023
Ben Gamari pushed to branch wip/clear-block-info at Glasgow Haskell Compiler / GHC
Commits:
a81a4ad1 by Ben Gamari at 2023-05-10T15:28:18-04:00
rts: Clear block_info when unblocking
Otherwise we may end up with dangling pointers which may complicate
debugging.
- - - - -
5 changed files:
- rts/RaiseAsync.c
- rts/Schedule.c
- rts/Threads.c
- rts/posix/Select.c
- rts/win32/AsyncMIO.c
Changes:
=====================================
rts/RaiseAsync.c
=====================================
@@ -729,6 +729,7 @@ removeFromQueues(Capability *cap, StgTSO *tso)
done:
tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
appendToRunQueue(cap, tso);
}
@@ -1092,6 +1093,7 @@ done:
// wake it up
if (tso->why_blocked != NotBlocked) {
tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
appendToRunQueue(cap,tso);
}
=====================================
rts/Schedule.c
=====================================
@@ -2565,7 +2565,8 @@ resumeThread (void *task_)
traceEventRunThread(cap, tso);
/* Reset blocking status */
- tso->why_blocked = NotBlocked;
+ tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
if ((tso->flags & TSO_BLOCKEX) == 0) {
// avoid locking the TSO if we don't have to
=====================================
rts/Threads.c
=====================================
@@ -334,6 +334,7 @@ unblock:
// just run the thread now, if the BH is not really available,
// we'll block again.
tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
appendToRunQueue(cap,tso);
// We used to set the context switch flag here, which would
=====================================
rts/posix/Select.c
=====================================
@@ -106,6 +106,7 @@ static bool wakeUpSleepingThreads (Capability *cap, LowResTime now)
}
iomgr->sleeping_queue = tso->_link;
tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
tso->_link = END_TSO_QUEUE;
IF_DEBUG(scheduler, debugBelch("Waking up sleeping thread %"
FMT_StgThreadID "\n", tso->id));
@@ -437,6 +438,7 @@ awaitEvent(Capability *cap, bool wait)
debugBelch("Waking up blocked thread %" FMT_StgThreadID "\n",
tso->id));
tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
tso->_link = END_TSO_QUEUE;
pushOnRunQueue(cap,tso);
break;
=====================================
rts/win32/AsyncMIO.c
=====================================
@@ -318,14 +318,16 @@ start:
: END_TSO_QUEUE;
}
- // Terminates the run queue + this inner for-loop.
- tso->_link = END_TSO_QUEUE;
- tso->why_blocked = NotBlocked;
// save the StgAsyncIOResult in the
// stg_block_async_info stack frame, because
// the block_info field will be overwritten by
// pushOnRunQueue().
tso->stackobj->sp[1] = (W_)tso->block_info.async_result;
+
+ tso->why_blocked = NotBlocked;
+ tso->block_info.closure = (StgClosure *)END_TSO_QUEUE;
+ // Terminates the run queue + this inner for-loop.
+ tso->_link = END_TSO_QUEUE;
pushOnRunQueue(&MainCapability, tso);
break;
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a81a4ad1e9a222081b2f648d53faac37dfdc9736
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a81a4ad1e9a222081b2f648d53faac37dfdc9736
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230510/b566a626/attachment-0001.html>
More information about the ghc-commits
mailing list