Skip to content

fix(kernel): a stop waits for the step in flight and ends it - #588

Open
EnriqueParodi wants to merge 3 commits into
mainfrom
fix/kernel-stop-in-step-main
Open

EnriqueParodi wants to merge 3 commits into
mainfrom
fix/kernel-stop-in-step-main

Conversation

@EnriqueParodi

@EnriqueParodi EnriqueParodi commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

kernel-stop-in-step: a component asking the kernel to stop from inside a virtual-time step could hang the process forever.

doStop stopped the components while the clock driving the step still had calls to make, so the step's flush waited for an answer from a component already gone. A step gate now stands in front of the clock calls: the stop closes it, waits for the call under way, flushes the step that call left owing, and only then stops the components.

A component can ask the kernel to stop from inside a virtual-time step, while
the clock driving that step still has calls to make. doStop stopped the
components under those calls, so the step's flush waited for an answer from a
component already gone, and the process never exited.

A step gate now stands in front of the clock calls. The stop closes it, waits
for the call under way, and flushes the step that call left owing; only then do
the components stop, so no call is ever left waiting for one that has gone.
advanceTimeDrainInputsAndUpdate and flushVirtualTime report this to their
caller, which takes no step and names no next one once the kernel is stopping.

The test drives three components in separate groups, holding the step open
until the stop has reached the component that asked for it. It requires the
step the stop was asked in to be the last any component took, and to have been
flushed.
The comments explained the change rather than the code, in the past tense, and
repeated the step gate's reason in three places. The reason is stated once now,
beside the members it guards, and the names carry the rest.
The gate notified every waiter each time a clock call ended, which is once per
step on the kernel's own path. Only finishStepInFlight waits, and only the one
thread that gets through doStop reaches it, so there is never more than one.
@EnriqueParodi
EnriqueParodi marked this pull request as ready for review November 10, 2026 13:16
@EnriqueParodi EnriqueParodi self-assigned this Nov 10, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

}

public:
std::shared_ptr<Stepper> object;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable object has public visibility


public:
std::shared_ptr<Stepper> object;
std::shared_ptr<sen::ObjectSource> source;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable source has public visibility

public:
std::shared_ptr<Stepper> object;
std::shared_ptr<sen::ObjectSource> source;
std::atomic<int> steps {0};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-non-private-member-variables-in-classes ❌
member variable steps has public visibility

#include "sen/kernel/test_kernel.h"

// generated code
#include "stl/sen/kernel/kernel_objects.stl.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ misc-include-cleaner ❌
no header providing "sen::kernel::RunMode" is directly included

Suggested change
#include "stl/sen/kernel/kernel_objects.stl.h"
#include "stl/sen/kernel/basic_types.stl.h"
#include "stl/sen/kernel/kernel_objects.stl.h"

{
// The threads cannot be joined, so this ends the binary here. The counters say which hang it is:
// steps at stopStep with the stop asked is this test's, less means the run never got there.
std::fprintf(stderr,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ hicpp-vararg ❌
do not call c-style vararg functions

This branch has not been deployed

No deployments
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