Skip to content

Commit

Permalink
Merge pull request #5288 from gabilang/improve-strand-bbe
Browse files Browse the repository at this point in the history
Improve strand BBE
  • Loading branch information
warunalakshitha authored Sep 7, 2024
2 parents 75eef0f + 19983f2 commit 3b0dd06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 9 additions & 2 deletions examples/strands/strands.bal
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ function userSpeakerService(string userName) {
}

public function main() {

io:println("In function worker");

// By default, named workers are multitasked cooperatively, not preemptively.
// Each named worker has a `strand` (a logical thread of control) and
// Each named worker has a strand (a logical thread of control) and
// the execution switches between strands only at specific `yield` points.
worker A {
io:println("In worker A");
Expand All @@ -23,5 +26,9 @@ public function main() {
io:println("Worker B end");
}

io:println("In function worker");
// Explicitly wait for named workers to complete.
// This guarantees that the Ballerina program will not terminate till
// the workers have completed their execution.
wait A;
wait B;
}
2 changes: 0 additions & 2 deletions examples/strands/strands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

By default, named workers are multitasked cooperatively, not preemptively. Each named worker has a "strand" (logical thread of control) and execution switches between strands only at specific "yield" points such as doing a wait or when a library function invokes a system call that would block.

This avoids the need for users to lock variables that are accessed from multiple named workers. An annotation can be used to make a strand run on a separate thread.

::: code strands.bal :::

::: out strands.out :::

0 comments on commit 3b0dd06

Please sign in to comment.