File tree 1 file changed +17
-2
lines changed
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -59,21 +59,32 @@ pub fn run_in_newsched_task(f: ~fn()) {
59
59
/// in one of the schedulers. The schedulers will stay alive
60
60
/// until the function `f` returns.
61
61
pub fn run_in_mt_newsched_task ( f : ~fn ( ) ) {
62
+ use libc;
63
+ use os;
64
+ use from_str:: FromStr ;
62
65
use rt:: uv:: uvio:: UvEventLoop ;
63
66
use rt:: sched:: Shutdown ;
64
67
65
68
let f_cell = Cell ( f) ;
66
69
67
70
do run_in_bare_thread {
68
- static N : uint = 4 ;
71
+ let nthreads = match os:: getenv ( "RUST_TEST_THREADS" ) {
72
+ Some ( nstr) => FromStr :: from_str ( nstr) . get ( ) ,
73
+ None => unsafe {
74
+ // Using more threads than cores in test code
75
+ // to force the OS to preempt them frequently.
76
+ // Assuming that this help stress test concurrent types.
77
+ rust_get_num_cpus ( ) * 2
78
+ }
79
+ } ;
69
80
70
81
let sleepers = SleeperList :: new ( ) ;
71
82
let work_queue = WorkQueue :: new ( ) ;
72
83
73
84
let mut handles = ~[ ] ;
74
85
let mut scheds = ~[ ] ;
75
86
76
- for uint:: range( 0 , N ) |_| {
87
+ for uint:: range( 0 , nthreads ) |_| {
77
88
let loop_ = ~UvEventLoop :: new ( ) ;
78
89
let mut sched = ~Scheduler :: new ( loop_, work_queue. clone ( ) , sleepers. clone ( ) ) ;
79
90
let handle = sched. make_handle ( ) ;
@@ -111,6 +122,10 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
111
122
// Wait for schedulers
112
123
let _threads = threads;
113
124
}
125
+
126
+ extern {
127
+ fn rust_get_num_cpus ( ) -> libc:: uintptr_t ;
128
+ }
114
129
}
115
130
116
131
/// Test tasks will abort on failure instead of unwinding
You can’t perform that action at this time.
0 commit comments