File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 1
1
use num_format:: { Locale , ToFormattedString } ;
2
+ use std:: env;
2
3
use std:: sync:: atomic:: { AtomicBool , AtomicU64 , Ordering } ;
3
4
use std:: sync:: Arc ;
4
5
use std:: thread;
28
29
STOP . store ( true , Ordering :: SeqCst ) ;
29
30
} )
30
31
. expect ( "Error setting Ctrl-C handler" ) ;
31
- let num_threads = num_cpus:: get ( ) ;
32
+
33
+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
34
+
35
+ let mut num_threads = num_cpus:: get ( ) ;
36
+ if args. len ( ) == 2 {
37
+ let arg = args[ 1 ] . parse :: < i32 > ( ) . unwrap ( ) ;
38
+
39
+ if arg > 0 && arg <= num_threads as i32 {
40
+ num_threads = arg as usize ;
41
+ } else {
42
+ eprintln ! ( "Invalid command line argument {} as number of threads. Make sure the value is above 0 and less than or equal to {}." , arg, num_threads) ;
43
+ std:: process:: exit ( 1 ) ;
44
+ }
45
+ }
46
+
32
47
println ! ( "Number of threads: {}\n " , num_threads) ;
33
48
let mut handles = Vec :: with_capacity ( num_threads) ;
34
49
let func_arc = Arc :: new ( func) ;
You can’t perform that action at this time.
0 commit comments