Changeset f2cb80a in mainline for kernel/test/thread/thread1.c


Ignore:
Timestamp:
2024-02-23T17:57:23Z (11 months ago)
Author:
GitHub <noreply@…>
Children:
192019f
Parents:
86f862c (diff), 90ba06c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2024-02-23 17:57:23)
git-committer:
GitHub <noreply@…> (2024-02-23 17:57:23)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/thread/thread1.c

    r86f862c rf2cb80a  
    3838
    3939static atomic_bool finish;
    40 static atomic_size_t threads_finished;
    4140
    4241static void threadtest(void *data)
     
    4645                thread_usleep(100000);
    4746        }
    48         atomic_inc(&threads_finished);
    4947}
    5048
    5149const char *test_thread1(void)
    5250{
    53         unsigned int i;
    54         size_t total = 0;
     51        atomic_store(&finish, true);
    5552
    56         atomic_store(&finish, true);
    57         atomic_store(&threads_finished, 0);
     53        thread_t *threads[THREADS] = { };
    5854
    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 {
    6362                        TPRINTF("Could not create thread %d\n", i);
    6463                        break;
    6564                }
    66                 thread_ready(t);
    67                 total++;
    6865        }
    6966
     
    7269
    7370        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);
    7777        }
    7878
Note: See TracChangeset for help on using the changeset viewer.