Quellcode durchsuchen

Threads now count correctly. Verbose flag missing.

Joshua Rutschmann vor 8 Jahren
Ursprung
Commit
13d06c0f83
1 geänderte Dateien mit 13 neuen und 11 gelöschten Zeilen
  1. 13
    11
      hw8/task1/src/main.rs

+ 13
- 11
hw8/task1/src/main.rs Datei anzeigen

@@ -31,10 +31,7 @@ pub fn main() {
31 31
 
32 32
     if true {
33 33
         println!("--------------------------------------------");
34
-        println!(
35
-            "Container:    : \"{}\"",
36
-            sys_info::hostname().unwrap_or("-".to_string())
37
-        );
34
+        println!("Container: \"{}\"", sys_info::hostname().unwrap_or("-".to_string()));
38 35
         println!("Physical CPUs : {}", sys_info::cpu_num().unwrap_or(0));
39 36
         println!("Logical CPUs  : {}", sys_info::cpu_num().unwrap_or(0));
40 37
         println!("CPU Speed     : {}", sys_info::cpu_speed().unwrap_or(0));
@@ -59,11 +56,12 @@ pub fn main() {
59 56
                 let tx = tx.clone();
60 57
 
61 58
                 children.push(thread::spawn(move || {
62
-                    let from = max / t * i;
63
-                    let to = max / t * (i + 1);
64
-                    println!("{} - {} | Thread {} | Difficulty is: {}", from, to, i, d);
65
-
66
-                    for n in from..to {
59
+                    let mut n = i;
60
+                    while n < max {
61
+                        if n < 20 {
62
+                            println!("Thread {}: {}", i, n);
63
+                        }
64
+                        
67 65
                         if let Some(x) = verify_product(b, n, &d) {
68 66
                             let end = get_time();
69 67
                             println!("Number: {} --> hash: {}", x.number, x.hash);
@@ -76,6 +74,7 @@ pub fn main() {
76 74
                             }
77 75
                             tx.send("Finished").unwrap();
78 76
                         }
77
+                        n += t;
79 78
                     }
80 79
 
81 80
                 }));
@@ -87,7 +86,6 @@ pub fn main() {
87 86
                 }
88 87
                 Err(_) => {}
89 88
             }
90
-
91 89
             /*
92 90
             for child in children {
93 91
                 let _ = child.join();
@@ -135,7 +133,11 @@ fn create_app<'a, 'b>() -> App<'a, 'b> {
135 133
                 .takes_value(true)
136 134
                 .required(false),
137 135
         )
138
-        .subcommand(
136
+	.arg(Arg::with_name("verbose")
137
+       		.short("v")
138
+        	.multiple(true)
139
+        )
140
+	.subcommand(
139 141
             SubCommand::with_name("timings")
140 142
                 .about("controls timing features")
141 143
                 .version("1.0")

Laden…
Abbrechen
Speichern