Changeset 0f4f1b2 in mainline for kernel/test/thread/thread1.c
- Timestamp:
- 2024-01-15T17:10:27Z (11 months ago)
- Branches:
- master
- Children:
- e82879c
- Parents:
- a064d4f
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 16:37:22)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 17:10:27)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/thread/thread1.c
ra064d4f r0f4f1b2 38 38 39 39 static atomic_bool finish; 40 static atomic_size_t threads_finished;41 40 42 41 static void threadtest(void *data) … … 46 45 thread_usleep(100000); 47 46 } 48 atomic_inc(&threads_finished);49 47 } 50 48 51 49 const char *test_thread1(void) 52 50 { 53 unsigned int i; 54 size_t total = 0; 51 atomic_store(&finish, true); 55 52 56 atomic_store(&finish, true); 57 atomic_store(&threads_finished, 0); 53 thread_t *threads[THREADS] = { }; 58 54 59 for (i = 0; i < THREADS; i++) { 60 thread_t *t; 61 if (!(t = thread_create(threadtest, NULL, TASK, 62 THREAD_FLAG_NONE, "threadtest"))) { 55 for (int i = 0; i < THREADS; i++) { 56 threads[i] = thread_create(threadtest, NULL, 57 TASK, THREAD_FLAG_NONE, "threadtest"); 58 59 if (threads[i]) { 60 thread_start(threads[i]); 61 } else { 63 62 TPRINTF("Could not create thread %d\n", i); 64 63 break; 65 64 } 66 thread_ready(t);67 total++;68 65 } 69 66 … … 72 69 73 70 atomic_store(&finish, false); 74 while (atomic_load(&threads_finished) < total) { 75 TPRINTF("Threads left: %zu\n", total - atomic_load(&threads_finished)); 76 thread_sleep(1); 71 72 for (int i = 0; i < THREADS; i++) { 73 if (threads[i] != NULL) 74 thread_join(threads[i]); 75 76 TPRINTF("Threads left: %d\n", THREADS - i - 1); 77 77 } 78 78
Note:
See TracChangeset
for help on using the changeset viewer.