[flang] Fix length handling in character kind implicit conversion (#74586)
[llvm-project.git] / libc / test / integration / src / threads / thrd_test.cpp
blob58728366b53ee6c2ccfdbd60929149207f1ca762
1 //===-- Tests for thrd_t creation and joining -----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/threads/thrd_create.h"
10 #include "src/threads/thrd_join.h"
12 #include "test/IntegrationTest/test.h"
14 #include <threads.h>
16 static constexpr int thread_count = 1000;
17 static int counter = 0;
18 static int thread_func(void *) {
19 ++counter;
20 return 0;
23 void create_and_join() {
24 for (counter = 0; counter <= thread_count;) {
25 thrd_t thread;
26 int old_counter_val = counter;
27 ASSERT_EQ(LIBC_NAMESPACE::thrd_create(&thread, thread_func, nullptr),
28 (int)thrd_success);
29 int retval = thread_count + 1; // Start with a retval we dont expect.
30 ASSERT_EQ(LIBC_NAMESPACE::thrd_join(thread, &retval), (int)thrd_success);
31 ASSERT_EQ(retval, 0);
32 ASSERT_EQ(counter, old_counter_val + 1);
36 static int return_arg(void *arg) { return *reinterpret_cast<int *>(arg); }
38 void spawn_and_join() {
39 thrd_t thread_list[thread_count];
40 int args[thread_count];
42 for (int i = 0; i < thread_count; ++i) {
43 args[i] = i;
44 ASSERT_EQ(
45 LIBC_NAMESPACE::thrd_create(thread_list + i, return_arg, args + i),
46 (int)thrd_success);
49 for (int i = 0; i < thread_count; ++i) {
50 int retval = thread_count + 1; // Start with a retval we dont expect.
51 ASSERT_EQ(LIBC_NAMESPACE::thrd_join(thread_list[i], &retval),
52 (int)thrd_success);
53 ASSERT_EQ(retval, i);
57 TEST_MAIN() {
58 create_and_join();
59 spawn_and_join();
60 return 0;