Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve shutdown behavior (enable clean shutdowns) #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anonymouspage
Copy link

The two commits in this PR have their own commentary describing the changes that can be referred to, but to quickly summarize, this PR enables clean shutdowns of the reflector. The current code has no way of performing a clean shutdown for a couple reasons: (1) infinite loops in main() and (2) long blocking sleeps in various worker threads.

The general approach was to swap the blocking sleeps with condition variables that are signaled during shutdown, and to add signal handling in the main thread for termination signals. With these changes the reflector shuts down cleanly in less than a second with run as a daemon or in the foreground (when in the foreground, CTRL-C will initiate the shutdown).

Mark Landis (N6AZX) added 2 commits January 1, 2023 20:36
This commit is the first in a small series to improve the shutdown
behavior of xlxd.

(1) Ensures worker threads block signals by masking all signals prior
    to the main reflector startup via CReflector::Start().

(2) Uses sigwaitinfo() in the main thread to wait on a few normal
    termination signals. This works for both daemon and non-daemon
    operation.
Second patch in the improve-shutdown series. This replaces blocking
sleeps with the use of condition variables for signaling thread
shutdown. The details are:

(1) Create CSimpleCondition class to provide a very basic (simple)
    condition variable that can be used in situations where external
    mutex control is not required, i.e., the class contains both a
    managed mutex and condition variable. Instances of this class
    can be used for basic signaling, and waiters can specify user
    defined predicates.

(2) Replace instances of large sleeps in worker threads with use of
    CSimpleCondition. This allows for very quick response times from
    worker threads when a shutdown has been initiated.

(3) Change stop thread booleans to atomic_bool.

(4) Fixes small whitespace discprencies.
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.

1 participant