40 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// <semaphore>13 14#include <cassert>15#include <semaphore>16#include <thread>17 18#include "make_test_thread.h"19#include "test_macros.h"20 21int main(int, char**)22{23 std::counting_semaphore<> s(1);24 25 assert(s.try_acquire());26 assert(!s.try_acquire());27 s.release();28 assert(s.try_acquire());29 assert(!s.try_acquire());30 s.release(2);31 std::thread t = support::make_test_thread([&](){32 assert(s.try_acquire());33 });34 t.join();35 assert(s.try_acquire());36 assert(!s.try_acquire());37 38 return 0;39}40