Skip to content

Commit

Permalink
Merge #182
Browse files Browse the repository at this point in the history
182: Demo: Add overaligned thread-local storage r=stlankes a=mkroening



Co-authored-by: Martin Kröning <mkroening@posteo.net>
  • Loading branch information
bors[bot] and mkroening committed Dec 5, 2021
2 parents acf1ee4 + c8a4c57 commit 3056caf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/demo/src/main.rs
@@ -1,6 +1,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![feature(thread_id_value)]
#![feature(thread_local_const_init)]

#[cfg(target_os = "hermit")]
extern crate hermit_sys;
Expand All @@ -23,6 +24,11 @@ fn test_result<T>(result: Result<(), T>) -> &'static str {

fn main() {
println!("Test {} ... {}", stringify!(hello), test_result(hello()));
println!(
"Test {} ... {}",
stringify!(test_thread_local),
test_result(test_thread_local())
);
println!(
"Test {} ... {}",
stringify!(arithmetic),
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/matrix_multiplication.rs
@@ -1,6 +1,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![feature(thread_id_value)]
#![feature(thread_local_const_init)]

#[cfg(target_os = "hermit")]
extern crate hermit_sys;
Expand Down
1 change: 1 addition & 0 deletions examples/demo/src/pi_sequential.rs
@@ -1,6 +1,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![feature(thread_id_value)]
#![feature(thread_local_const_init)]

#[cfg(target_os = "hermit")]
extern crate hermit_sys;
Expand Down
2 changes: 2 additions & 0 deletions examples/demo/src/tests/mod.rs
Expand Up @@ -16,8 +16,10 @@ use syscalls::SYS_getpid;

mod laplace;
mod matmul;
mod thread_local;

pub use matmul::test_matmul_strassen;
pub use thread_local::test_thread_local;

pub fn thread_creation() -> Result<(), ()> {
const N: usize = 10;
Expand Down
14 changes: 14 additions & 0 deletions examples/demo/src/tests/thread_local.rs
@@ -0,0 +1,14 @@
pub fn test_thread_local() -> Result<(), ()> {
#[repr(align(0x1000))]
struct OverAligned(u8);

thread_local! {
static THREAD_LOCAL: OverAligned = const { OverAligned(0x42) };
}

THREAD_LOCAL.with(|thread_local| {
assert_eq!(0x42, thread_local.0);
});

Ok(())
}

0 comments on commit 3056caf

Please sign in to comment.