MCPcopy Create free account
hub / github.com/elast0ny/shared_memory / main

Function main

examples/mutex.rs:20–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20fn main() {
21 env_logger::init();
22 let args = Args::parse();
23
24 if args.num_threads < 1 {
25 eprintln!("num_threads should be 2 or more");
26 return;
27 }
28 let mut threads = Vec::with_capacity(args.num_threads);
29 let _ = std::fs::remove_file("mutex_mapping");
30
31 // Spawn N threads
32 for i in 0..args.num_threads {
33 let thread_id = i + 1;
34 threads.push(thread::spawn(move || {
35 increment_value("mutex_mapping", thread_id);
36 }));
37 }
38
39 // Wait for threads to exit
40 for t in threads.drain(..) {
41 t.join().unwrap();
42 }
43}
44
45fn increment_value(shmem_flink: &str, thread_num: usize) {
46 // Create or open the shared memory mapping

Callers

nothing calls this directly

Calls 1

increment_valueFunction · 0.70

Tested by

no test coverage detected