-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readme file and some documentation to stdlib
- Loading branch information
Showing
4 changed files
with
101 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Rust bindings for Lunatic's stdlib | ||
|
||
This library contains higher level wrappers for low level Lunatic syscalls. | ||
|
||
Currently it requires nightly. | ||
|
||
### Example | ||
|
||
Create 100k processes and calculate the power of numbers then send the results back to the original process. | ||
|
||
```rust | ||
use lunatic::{Channel, Process}; | ||
|
||
fn main() { | ||
let channel = Channel::new(0); | ||
|
||
for i in 0..100_000 { | ||
let x = channel.clone(); | ||
Process::spawn(move || { | ||
x.send((i, power(i))); | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
for _ in 0..100_000 { | ||
let (i, power) = channel.receive(); | ||
println!("Power of {} is {}", i, power); | ||
} | ||
} | ||
|
||
fn power(a: i32) -> i32 { | ||
a * a | ||
} | ||
|
||
``` | ||
|
||
Compile your app with: | ||
|
||
``` | ||
cargo build --release --target=wasm32-wasi | ||
``` | ||
|
||
and run it with | ||
|
||
``` | ||
lunatic target/wasm32-wasi/release/<name>.wasm | ||
``` |
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
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