blob: d46d6ae47719bbee8e7bbca4dc0a507ff0bc417d [file] [log] [blame]
Olivier Giroux54fa9ec2020-02-18 09:58:34 -05001//===----------------------------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8//
9// UNSUPPORTED: libcpp-has-no-threads
10// UNSUPPORTED: c++98, c++03, c++11
11
12// <semaphore>
13
14#include <semaphore>
15#include <chrono>
16#include <thread>
17
18#include "test_macros.h"
19
20int main(int, char**)
21{
22 std::binary_semaphore s(1);
23
24 auto l = [&](){
25 for(int i = 0; i < 1024; ++i) {
26 s.acquire();
27 std::this_thread::sleep_for(std::chrono::microseconds(1));
28 s.release();
29 }
30 };
31
32 std::thread t(l);
33 l();
34
35 t.join();
36
37 return 0;
38}