-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ef3525
commit e52ff14
Showing
8 changed files
with
975 additions
and
8 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
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,50 @@ | ||
# Behaviour-Oriented Concurrency (BoC) | ||
**Implement a runtime for Behaviour-Oriented Concurrency** | ||
|
||
> *The Behaviour-Oriented Concurrency paradigm: a concurrency paradigm | ||
> that achieves flexible coordination over multiple resources, and ordered execution, and scalability.* (from §1 of the BoC [paper](https://doi.org/10.1145/3622852)) | ||
First, read [the original BoC paper](https://doi.org/10.1145/3622852) and understand its algorithm. | ||
In particular, you should understand the key concepts (e.g., cown, behaviour, when, and thunk), and fully understand `Fig.3` and `§4.3` which contain the details of the implementation. | ||
|
||
Fill in the `todo!()`s in `src/boc.rs`. | ||
The total lines of code to be written is about 70. | ||
Your implementation should satisfy the following criterias: | ||
* when clauses should be scheduled in the correct order of the *dependency graph* (§4.1). | ||
* Your implementation of the BoC runtime should ensure *deadlock freedom*. | ||
We will test the deadlock freedom by several stress tests with timeouts. | ||
* Whenever you want to spawn a new thread, **don't use** [`std::thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html). | ||
Instead, use [`rayon::spawn`](https://docs.rs/rayon/latest/rayon/fn.spawn.html). | ||
|
||
We provide several ways of using the when clause in Rust, illustrated below. | ||
|
||
1. Using the `when!` macro. Below is a representative example describing its use: | ||
|
||
```rust | ||
when!(c1, c2; g1, g2; { | ||
... // thunk | ||
}); | ||
``` | ||
This results in a when clause that schedules a new behavior for two `CownPtr`s `c1` and `c2`. | ||
`g1` and `g2` are mutable references to the shared resources protected by given `CownPtr`s | ||
and can be used in the thunk. | ||
2. Using the `run_when` function directly. Use this if you want to create a new behavior with an arbitrary number of `CownPtr`s. | ||
For example, | ||
|
||
```rust | ||
run_when(vec![c1.clone(), c2.clone(), c3.clone()], move |mut acc| { | ||
... // thunk | ||
}); | ||
``` | ||
The first argument is a `Vec` of cowns with the same type. | ||
`acc` is a vector of mutable references to the shared resources protected by the cowns, | ||
and it is guaranteed that `acc` has the same length as the specified given `Vec` of `CownPtr`s. | ||
|
||
More examples can be found in `src/boc.rs` and `test/boc.rs`. | ||
|
||
## Grading (100 points) | ||
Run `./scripts/grade-boc.sh`. | ||
Basic tests account for 60 points and stress tests account for 40 points. | ||
|
||
## Submission | ||
Submit `boc.rs` to gg. |
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
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,75 @@ | ||
#!/usr/bin/env bash | ||
# set -e | ||
set -uo pipefail | ||
IFS=$'\n\t' | ||
|
||
# Imports library. | ||
BASEDIR=$(dirname "$0") | ||
source $BASEDIR/grade-utils.sh | ||
|
||
run_linters || exit 1 | ||
|
||
lines=$(grep_skip_comment "thread::spawn" "$BASEDIR/../src/boc.rs") | ||
if [ -n "$lines" ]; then | ||
echo "thread::spawn(...) is not allowed." | ||
echo "$lines" | ||
exit 1 | ||
fi | ||
|
||
RUNNERS=( | ||
"cargo" | ||
"cargo --release" | ||
"cargo_asan" | ||
"cargo_asan --release" | ||
) | ||
TIMEOUT=180s | ||
SCORE=0 | ||
|
||
echo "1. Basic tests" | ||
|
||
TESTS=( | ||
"--doc boc" | ||
"--test boc -- --exact basic_test::message_passing_test" | ||
"--test boc -- --exact basic_test::message_passing_determines_order" | ||
"--test boc -- --exact basic_test::merge_sort_basic_test" | ||
"--test boc -- --exact basic_test::fibonacci_basic_test" | ||
"--test boc -- --exact basic_test::banking_basic_test" | ||
) | ||
|
||
basic_test_failed=false | ||
|
||
for RUNNER in "${RUNNERS[@]}"; do | ||
echo "Running with $RUNNER, timeout $TIMEOUT..." | ||
if [ $(run_tests) -ne 0 ]; then | ||
basic_test_failed=true | ||
break | ||
fi | ||
done | ||
|
||
if [ "$basic_test_failed" = false ]; then | ||
SCORE=$((SCORE + 60)) | ||
fi | ||
|
||
echo "2. Stress tests" | ||
|
||
TESTS=( | ||
"--test boc -- --exact stress_test::merge_sort_stress_test" | ||
"--test boc -- --exact stress_test::fibonacci_stress_test" | ||
"--test boc -- --exact stress_test::banking_stress_test" | ||
) | ||
|
||
stress_test_failed=false | ||
|
||
for RUNNER in "${RUNNERS[@]}"; do | ||
echo "Running with $RUNNER, timeout $TIMEOUT..." | ||
if [ $(run_tests) -ne 0 ]; then | ||
stress_test_failed=true | ||
break | ||
fi | ||
done | ||
|
||
if [ "$stress_test_failed" = false ]; then | ||
SCORE=$((SCORE + 40)) | ||
fi | ||
|
||
echo "Score: $SCORE / 100" |
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
Oops, something went wrong.