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

Fix crash if a Context is stopped immediately after creation #120

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/team766/framework/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ private void transferControl(final ControlOwner thisOwner, final ControlOwner de
* This is the entry point for this Context's worker thread.
*/
private void threadFunction() {
// OS threads run independently of one another, so we need to wait until
// the baton is passed to us before we can start running the user's code
waitForControl(ControlOwner.SUBROUTINE);
try {
// OS threads run independently of one another, so we need to wait until
// the baton is passed to us before we can start running the user's code
waitForControl(ControlOwner.SUBROUTINE);
// Call into the user's code.
m_func.run(this);
Logger.get(Category.FRAMEWORK)
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/team766/framework/ContextTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.team766.framework;

import com.team766.TestCase;
import org.junit.jupiter.api.Test;

public class ContextTest extends TestCase {
/// Regression test: calling stop() on a Context before it is allowed to
/// run the first time should not crash the program.
@Test
public void testStopOnFirstTick() {
var lc = Scheduler.getInstance().startAsync(Procedure.NO_OP);
lc.stop();

step();

assertTrue(lc.isDone());
}
}
Loading