Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo: Add overaligned thread-local storage #182

Merged
merged 1 commit into from Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(())
}