-
Notifications
You must be signed in to change notification settings - Fork 0
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
494d3e7
commit 3b1f966
Showing
6 changed files
with
154 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
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,30 @@ | ||
|
||
|
||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
use std::thread; | ||
|
||
use enclose::enc; | ||
use enclose::enclose; | ||
|
||
|
||
fn main() { | ||
let v = Arc::new(Mutex::new( 0 )); | ||
let thread = thread::spawn( enc!((v) move || { | ||
let mut v_lock = match v.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
*v_lock += 1; | ||
})); | ||
|
||
thread.join().unwrap(); | ||
{ | ||
let v_lock = match v.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
assert_eq!(*v_lock, 1); | ||
} | ||
} | ||
|
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,27 @@ | ||
|
||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
use std::thread; | ||
|
||
use enclose::enc; | ||
use enclose::enclose; | ||
|
||
fn main() { | ||
let v = Arc::new(Mutex::new( 0 )); | ||
let thread = thread::spawn( enc!((v => MY_LOCKER) move || { | ||
let mut v_lock = match MY_LOCKER.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
*v_lock += 1; | ||
})); | ||
|
||
thread.join().unwrap(); | ||
{ | ||
let v_lock = match v.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
assert_eq!(*v_lock, 1); | ||
} | ||
} |
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,43 @@ | ||
|
||
|
||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
use std::sync::RwLock; | ||
use std::thread; | ||
|
||
use enclose::enc; | ||
use enclose::enclose; | ||
|
||
fn main() { | ||
|
||
let v = Arc::new(Mutex::new( 0 )); | ||
let v2 = Arc::new(RwLock::new( (0, 2, 3, 4) )); | ||
|
||
let count_thread = 5; | ||
let mut wait_all = Vec::with_capacity(count_thread); | ||
|
||
for _a in 0..count_thread { | ||
wait_all.push({ | ||
thread::spawn( enc!((v, v2) move || { | ||
let mut v_lock = match v.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
*v_lock += 1; | ||
|
||
drop( v2 ); //ignore warning | ||
})) | ||
}); | ||
} | ||
for a in wait_all { | ||
a.join().unwrap(); | ||
} | ||
{ | ||
//Test result | ||
let v_lock = match v.lock() { | ||
Ok(a) => a, | ||
Err(e) => e.into_inner(), | ||
}; | ||
assert_eq!(*v_lock, 5); | ||
} | ||
} |
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