Skip to content

Conversation

@Gerold103
Copy link
Owner

Part of #40.

The idea previously was that a worker thread can't leave the
scheduler role until the scheduler is stopped or there are tasks
to do.

But actually nothing prevents from leaving the scheduler, entering
it again, and then sleeping on waiting for tasks.

It allows to simplify the state machine of the scheduler a bit.
Gives a guarantee that the scheduler-role will consume the front
signal only once per scheduling iteration.

This guarantee in turn is going to be quite handy in the future
potential API improvement for making it possible to run the
scheduler in user's threads.

Part of #40
@Gerold103 Gerold103 self-assigned this May 19, 2025
Atomic "and" + "or" are going to be quite handy in the next
commits. They could be implemented manually, but it is much easier
to just take the STL version.

Needed for #40
@Gerold103 Gerold103 force-pushed the run-method-3-interruptible-mutex branch 7 times, most recently from 9d62641 to 86145f3 Compare May 20, 2025 20:22
Gerold103 added 4 commits May 20, 2025 22:36
The new class is a special type of mutex which allows to take the
lock, go to sleep on some arbitrary condition (a condition
variable, a epoll_wait() call, a Signal.ReceiveBlocking(), or
something similar), and then get woken up when other threads want
to take the ownership.

This is an abstraction of the TaskScheduler's usecase. The
scheduler workers are going to be taking the lock and sleeping
when have to wait for new tasks or for a deadline. And other
threads would forcefully take the ownership when need to do some
maintenance work like stop/start of the scheduler or getting
something out of the scheduler-role context.

Currently there isn't much of the second type of work, but this
will change in scope of #40.

Part of #40
It replaces the previously used atomic flag and does basically the
same at this point.

But in the future the lock's usage is going to be extended to do
more stuff in the scheduler.

Part of #40
Those methods repeat the ones from IOCore. It is the next step
towards allowing the user to run the scheduler in user-threads.

Part of #40
The socket closure consists of 2 steps:

- Set the close guard. If wasn't already set, the set CLOSING
    state.

- When see CLOSING state, ensure the close-guard is set and do the
    closure.

The close guard and CLOSING state were both set using the relaxed
memory order.

It could lead to races on ARM. One thread could set close-guard
and then CLOSING state. Another thread could see the CLOSING
state, but not see the close-guard being set yet.

Lets fix that by making those threads sync on the state (similar
to how signals work in TaskScheduler). The first thread would
release-write. And the second thread would acquire-read. Then the
close-guard is properly synced between them.

Closes #46
@Gerold103 Gerold103 force-pushed the run-method-3-interruptible-mutex branch from 86145f3 to 3c2a04f Compare May 20, 2025 20:48
@Gerold103 Gerold103 merged commit 1845eb0 into master May 20, 2025
24 checks passed
@Gerold103 Gerold103 deleted the run-method-3-interruptible-mutex branch May 20, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants