-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2429 from lf-lang/fix-concurrency
Fix Unintended Action Override
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule reactor-c
updated
4 files
+12 −14 | core/lf_token.c | |
+3 −0 | include/api/reaction_macros.h | |
+1 −1 | lingua-franca-ref.txt | |
+2 −1 | python/lib/pythontarget.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
target Python | ||
|
||
reactor ConcurrentActionTest { | ||
state logs | ||
physical action addlog_action | ||
|
||
reaction(startup) -> addlog_action {= | ||
print("Starting WebServer") | ||
import time | ||
import threading | ||
self.logs = [] | ||
def testall(): | ||
def test(i): | ||
print(f"Scheduling action {i}") | ||
addlog_action.schedule(0, f"{i}") | ||
|
||
threads = [] | ||
for j in range(100): | ||
self.logs = [] | ||
for i in range(100): | ||
test_thread = threading.Thread(target=test, args=(j*100 + i,)) | ||
test_thread.start() | ||
threads.append(test_thread) | ||
for thread in threads: | ||
thread.join() | ||
time.sleep(0.1) | ||
print(f"===== Test {j} complete =====") | ||
os._exit(0) | ||
testall_thread = threading.Thread(target=testall) | ||
testall_thread.start() | ||
=} | ||
|
||
reaction(addlog_action) {= | ||
if addlog_action.value in self.logs: | ||
print(f"Duplicate Action: {addlog_action.value}") | ||
raise Exception("Duplicate Action") | ||
else: | ||
print(f"Action: {addlog_action.value}") | ||
self.logs.append(addlog_action.value) | ||
=} | ||
} | ||
|
||
main reactor { | ||
server = new ConcurrentActionTest() | ||
} |