mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 01:59:14 +03:00
1682f0b760
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
42 lines
906 B
C++
42 lines
906 B
C++
/*
|
|
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Assertions.h>
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
#include <LibThread/Thread.h>
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
|
|
static void test_once()
|
|
{
|
|
constexpr size_t threads_count = 10;
|
|
|
|
static Vector<int> v;
|
|
v.clear();
|
|
pthread_once_t once = PTHREAD_ONCE_INIT;
|
|
NonnullRefPtrVector<LibThread::Thread, threads_count> threads;
|
|
|
|
for (size_t i = 0; i < threads_count; i++) {
|
|
threads.append(LibThread::Thread::construct([&] {
|
|
return pthread_once(&once, [] {
|
|
v.append(35);
|
|
sleep(1);
|
|
});
|
|
}));
|
|
threads.last().start();
|
|
}
|
|
for (auto& thread : threads)
|
|
[[maybe_unused]] auto res = thread.join();
|
|
|
|
VERIFY(v.size() == 1);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
test_once();
|
|
return 0;
|
|
}
|