Skip to content

Commit

Permalink
Backport HashedWheelTimerFix to .NET Standard 2.0
Browse files Browse the repository at this point in the history
Port akkadotnet#7174 to .NET Standard 2.0
  • Loading branch information
Aaronontheweb committed Apr 29, 2024
1 parent 9c63bfe commit b93c479
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/Akka/Actor/Scheduler/HashedWheelTimerScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ private void ProcessReschedule(long now)

private void Start()
{
if (_workerState == WORKER_STATE_STARTED) { } // do nothing
else if (_workerState == WORKER_STATE_INIT)
// only read the worker state once so it can't be a moving target for else-branch
var workerStateRead = _workerState;
if (workerStateRead == WORKER_STATE_STARTED) { } // do nothing
else if (workerStateRead == WORKER_STATE_INIT)
{
_worker ??= new Thread(Run) { IsBackground = true };
if (Interlocked.CompareExchange(ref _workerState, WORKER_STATE_STARTED, WORKER_STATE_INIT) ==
Expand All @@ -258,7 +260,7 @@ private void Start()
_worker.Start();
}
}
else if (_workerState is WORKER_STATE_SHUTDOWN)
else if (workerStateRead is WORKER_STATE_SHUTDOWN)
{
throw new SchedulerException("cannot enqueue after timer shutdown");
}
Expand Down

0 comments on commit b93c479

Please sign in to comment.