-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchallenge1.c
More file actions
44 lines (36 loc) · 1.1 KB
/
challenge1.c
File metadata and controls
44 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "uthread.h"
#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>
#include <assert.h>
void fpu_mode_worker(void *arg) {
int mode = (long)arg;
const char* mode_str = (mode == FE_UPWARD) ? "UPWARD" : "DOWNWARD";
// Set rounding mode
if (fesetround(mode) != 0) {
printf("Failed to set rounding mode\n");
exit(1);
}
for (int i = 0; i < 10000; i++) {
uthread_yield();
int current = fegetround();
if (current != mode) {
printf("[FAIL] Thread %s: Rounding mode corrupted! Expected %d, got %d\n",
mode_str, mode, current);
exit(1);
}
}
// printf("Thread %s passed.\n", mode_str);
}
int main() {
init_uthreads();
int num_threads = 20;
printf("Creating %d FPU mode threads...\n", num_threads);
for (int i = 0; i < num_threads; i++) {
int mode = (i % 2 == 0) ? FE_UPWARD : FE_DOWNWARD;
uthread_create(fpu_mode_worker, (void*)(long)mode, "FPU");
}
schedule();
printf("[PASS] FPU Mode Test Completed.\n");
return 0;
}