Skip to content

Instantly share code, notes, and snippets.

@bbatha
Created April 18, 2015 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbatha/8a1030c2d0f78be9eab1 to your computer and use it in GitHub Desktop.
Save bbatha/8a1030c2d0f78be9eab1 to your computer and use it in GitHub Desktop.
Life time error
[bbatha@dev threadpool-rs]% cargo test
Compiling threadpool v0.0.1 (file:///home/bbatha/projects/threadpool-rs)
src/lib.rs:42:12: 42:16 error: `pool` does not live long enough
src/lib.rs:42 pool.execute(move || {
^~~~
src/lib.rs:38:19: 47:6 note: reference must be valid for the block at 38:18...
src/lib.rs:38 fn it_works() {
src/lib.rs:39 let mut pool = ScopedThreadPool::new(2);
src/lib.rs:40
src/lib.rs:41 for _ in (0..3) {
src/lib.rs:42 pool.execute(move || {
src/lib.rs:43 thread::sleep_ms(1000);
...
src/lib.rs:39:49: 47:6 note: ...but borrowed value is only valid for the block suffix following statement 0 at 39:48
src/lib.rs:39 let mut pool = ScopedThreadPool::new(2);
src/lib.rs:40
src/lib.rs:41 for _ in (0..3) {
src/lib.rs:42 pool.execute(move || {
src/lib.rs:43 thread::sleep_ms(1000);
src/lib.rs:44 println!("Things are happening!");
...
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `threadpool`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment