Skip to content

Commit

Permalink
Publish hw4, update hw1
Browse files Browse the repository at this point in the history
  • Loading branch information
kingdoctor123 committed Mar 16, 2024
1 parent 5ef3525 commit e52ff14
Show file tree
Hide file tree
Showing 8 changed files with 975 additions and 8 deletions.
1 change: 1 addition & 0 deletions homework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ check-loom = ["loom"]
cfg-if = "1.0.0"
crossbeam-channel = "0.5.10"
crossbeam-epoch = "0.9.17"
rayon = "1.9.0"
ctrlc = { version = "3.4.2", optional = true }
cs431 = { git = "https://github.com/kaist-cp/cs431" }
# cs431 = { path = "../cs431" }
Expand Down
50 changes: 50 additions & 0 deletions homework/doc/boc.md
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.
5 changes: 4 additions & 1 deletion homework/doc/hello_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
The grader runs `./scripts/grade-hello_server.sh` in the `homework` directory.
This script runs the tests with various options.

There will be no partial scores for each module.
There will be no partial scores for `tcp` and `thread_pool` modules.
That is, you will get the score for a module only if your implementation passes **all** tests for that module.

On the other hand, we will give partial scores for `cache` module.
In particular, even if your implementation of `cache` blocks concurrent accesses to different keys, you can still get some points for basic functionalities.

## Submission
```bash
cd cs431/homework
Expand Down
75 changes: 75 additions & 0 deletions homework/scripts/grade-boc.sh
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"
32 changes: 25 additions & 7 deletions homework/scripts/grade-hello_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,34 @@ RUNNERS=(
)


t1_failed=false
t1_basic_failed=false
t1_nonblocking_failed=false
t2_failed=false
t3_failed=false

# Executes test for each runner.
for RUNNER in "${RUNNERS[@]}"; do
echo "Running with $RUNNER..."

if [ "$t1_failed" = false ]; then
echo " Testing cache.rs..."
TESTS=("--test cache")
if [ "$t1_basic_failed" = false ]; then
echo " Testing basic functionalities of cache.rs..."
TESTS=(
"--test cache -- --exact cache_no_duplicate_sequential"
"--test cache -- --exact cache_no_duplicate_concurrent"
)
if [ $(run_tests) -ne 0 ]; then
t1_failed=true
t1_basic_failed=true
fi
fi

if [ "$t1_nonblocking_failed" = false ]; then
echo " Testing nonblockingness of cache.rs..."
TESTS=(
"--test cache -- --exact cache_no_block_disjoint"
"--test cache -- --exact cache_no_reader_block"
)
if [ $(run_tests) -ne 0 ]; then
t1_nonblocking_failed=true
fi
fi

Expand All @@ -55,8 +70,11 @@ done
SCORE=0

# Scores for cache.rs
if [ "$t1_failed" = false ]; then
SCORE=$((SCORE + 40))
if [ "$t1_basic_failed" = false ]; then
SCORE=$((SCORE + 15))
fi
if [ "$t1_nonblocking_failed" = false ]; then
SCORE=$((SCORE + 25))
fi

# Scores for tcp.rs
Expand Down
Loading

0 comments on commit e52ff14

Please sign in to comment.