Skip to content

Commit 5b55e07

Browse files
author
Vytautas Astrauskas
committed
Add more concurrency tests.
1 parent 17f7bc8 commit 5b55e07

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Check that we terminate the program when the main thread terminates.
4+
5+
//~^^^^ ERROR: unsupported operation: the main thread terminated without waiting for other threads
6+
7+
#![feature(rustc_private)]
8+
9+
extern crate libc;
10+
11+
use std::{mem, ptr};
12+
13+
extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
14+
ptr::null_mut()
15+
}
16+
17+
fn main() {
18+
unsafe {
19+
let mut native: libc::pthread_t = mem::zeroed();
20+
let attr: libc::pthread_attr_t = mem::zeroed();
21+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
22+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Joining a detached thread is undefined behavior.
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate libc;
8+
9+
use std::{mem, ptr};
10+
11+
extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
12+
ptr::null_mut()
13+
}
14+
15+
fn main() {
16+
unsafe {
17+
let mut native: libc::pthread_t = mem::zeroed();
18+
let attr: libc::pthread_attr_t = mem::zeroed();
19+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
20+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
21+
assert_eq!(libc::pthread_detach(native), 0);
22+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join a detached or already joined thread
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Joining an already joined thread is undefined behavior.
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate libc;
8+
9+
use std::{mem, ptr};
10+
11+
extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
12+
ptr::null_mut()
13+
}
14+
15+
fn main() {
16+
unsafe {
17+
let mut native: libc::pthread_t = mem::zeroed();
18+
let attr: libc::pthread_attr_t = mem::zeroed();
19+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
20+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
21+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
22+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join a detached or already joined thread
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Joining the same thread multiple times is undefined behavior.
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate libc;
8+
9+
use std::thread;
10+
use std::{mem, ptr};
11+
12+
extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
13+
ptr::null_mut()
14+
}
15+
16+
fn main() {
17+
unsafe {
18+
let mut native: libc::pthread_t = mem::zeroed();
19+
let attr: libc::pthread_attr_t = mem::zeroed();
20+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
21+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
22+
let mut native_copy: libc::pthread_t = mem::zeroed();
23+
ptr::copy_nonoverlapping(&native, &mut native_copy, 1);
24+
let handle = thread::spawn(move || {
25+
assert_eq!(libc::pthread_join(native_copy, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join a detached or already joined thread
26+
});
27+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
28+
handle.join().unwrap();
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Joining itself is undefined behavior.
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate libc;
8+
9+
use std::ptr;
10+
11+
fn main() {
12+
unsafe {
13+
let native: libc::pthread_t = libc::pthread_self();
14+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join itself
15+
}
16+
}

0 commit comments

Comments
 (0)