-
Notifications
You must be signed in to change notification settings - Fork 352
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
81ea21b
commit f46921d
Showing
3 changed files
with
46 additions
and
24 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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
#![feature(thread_local)] | ||
|
||
use std::cell::Cell; | ||
|
||
pub fn main() { | ||
let a = 123; | ||
let b = Box::new(a); | ||
let r = Box::leak(b); | ||
|
||
thread_local! { | ||
static REF: Cell<Option<&'static i32>> = Cell::new(None); | ||
static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None); | ||
} | ||
|
||
REF.with(|cell| { | ||
cell.set(Some(r)); | ||
}) | ||
TLS_KEY.with(|cell| { | ||
cell.set(Some(Box::leak(Box::new(123)))); | ||
}); | ||
|
||
#[thread_local] | ||
static TLS: Cell<Option<&'static i32>> = Cell::new(None); | ||
|
||
TLS.set(Some(Box::leak(Box::new(123)))); | ||
} |