Skip to content

Commit

Permalink
Merge pull request #2429 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 20, 2024
2 parents ce42657 + 00464bf commit 8393142
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected void serializeAndSend(
result.pr(
"size_t _lf_message_length = "
+ sendRef
+ "->token->length * "
+ "->length * "
+ sendRef
+ "->token->type->element_size;");
result.pr(
Expand Down
45 changes: 45 additions & 0 deletions test/Python/src/concurrent/ConcurrentActionRepeat.lf
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()
}

0 comments on commit 8393142

Please sign in to comment.