Skip to content

Commit

Permalink
Merge pull request #2423 from lf-lang/fix-concurrency
Browse files Browse the repository at this point in the history
Fix Unintended Action Override
  • Loading branch information
lhstrh authored Oct 12, 2024
2 parents ee1be0c + 4baee5b commit a881e99
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/c/reactor-c
43 changes: 43 additions & 0 deletions test/Python/src/concurrent/ConcurrentAction.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 i in range(100):
test_thread = threading.Thread(target=test, args=(i,))
test_thread.start()
threads.append(test_thread)
for thread in threads:
thread.join()
print("Test complete")
time.sleep(2)
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()
}

0 comments on commit a881e99

Please sign in to comment.