Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// mutex& operator=(const mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::mutex m0;
|
||||
std::mutex m1;
|
||||
m1 = m0;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// mutex(const mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::mutex m0;
|
||||
std::mutex m1(m0);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// mutex();
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::mutex m;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// void lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock();
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// typedef pthread_mutex_t* native_handle_type;
|
||||
// native_handle_type native_handle();
|
||||
|
||||
#include <mutex>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::mutex m;
|
||||
pthread_mutex_t* h = m.native_handle();
|
||||
assert(h);
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class mutex;
|
||||
|
||||
// bool try_lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
while(!m.try_lock())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// recursive_mutex& operator=(const recursive_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_mutex m0;
|
||||
std::recursive_mutex m1;
|
||||
m1 = m0;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// recursive_mutex(const recursive_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_mutex m0;
|
||||
std::recursive_mutex m1(m0);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// recursive_mutex();
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_mutex m;
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// void lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::recursive_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock();
|
||||
time_point t1 = Clock::now();
|
||||
m.lock();
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// typedef pthread_mutex_t* native_handle_type;
|
||||
// native_handle_type native_handle();
|
||||
|
||||
#include <mutex>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_mutex m;
|
||||
pthread_mutex_t* h = m.native_handle();
|
||||
assert(h);
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_mutex;
|
||||
|
||||
// bool try_lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::recursive_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
while(!m.try_lock())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
assert(m.try_lock());
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
std::shared_timed_mutex m0;
|
||||
std::shared_timed_mutex m1;
|
||||
m1 = m0;
|
||||
#else
|
||||
# error
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// shared_timed_mutex(const shared_timed_mutex&) = delete;
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
std::shared_timed_mutex m0;
|
||||
std::shared_timed_mutex m1(m0);
|
||||
#else
|
||||
# error
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// shared_timed_mutex();
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
std::shared_timed_mutex m;
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// void lock();
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock();
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// void lock_shared();
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock_shared();
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock_shared();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock_shared();
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock_shared();
|
||||
ns d = t1 - t0;
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f));
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
m.lock_shared();
|
||||
for (auto& t : v)
|
||||
t = std::thread(g);
|
||||
std::thread q(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock_shared();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
q.join();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// bool try_lock();
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
while(!m.try_lock())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// template <class Rep, class Period>
|
||||
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// bool try_lock_shared();
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock_shared());
|
||||
assert(!m.try_lock_shared());
|
||||
assert(!m.try_lock_shared());
|
||||
while(!m.try_lock_shared())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock_shared();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f));
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// template <class Rep, class Period>
|
||||
// bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_shared_for(ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock_shared();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_shared_for(ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f1));
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f2));
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// template <class Clock, class Duration>
|
||||
// bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_shared_until(Clock::now() + ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock_shared();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_shared_until(Clock::now() + ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f1));
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::vector<std::thread> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(std::thread(f2));
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <shared_mutex>
|
||||
|
||||
// class shared_timed_mutex;
|
||||
|
||||
// template <class Clock, class Duration>
|
||||
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
std::shared_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// timed_mutex& operator=(const timed_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::timed_mutex m0;
|
||||
std::timed_mutex m1;
|
||||
m1 = m0;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// timed_mutex(const timed_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::timed_mutex m0;
|
||||
std::timed_mutex m1(m0);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// timed_mutex();
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::timed_mutex m;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// void lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock();
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// bool try_lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
while(!m.try_lock())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// template <class Rep, class Period>
|
||||
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class timed_mutex;
|
||||
|
||||
// template <class Clock, class Duration>
|
||||
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_timed_mutex m0;
|
||||
std::recursive_timed_mutex m1;
|
||||
m1 = m0;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// recursive_timed_mutex(const recursive_timed_mutex&) = delete;
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_timed_mutex m0;
|
||||
std::recursive_timed_mutex m1(m0);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// recursive_timed_mutex();
|
||||
|
||||
#include <mutex>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::recursive_timed_mutex m;
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// void lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::recursive_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
m.lock();
|
||||
time_point t1 = Clock::now();
|
||||
m.lock();
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// bool try_lock();
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::recursive_timed_mutex m;
|
||||
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
assert(!m.try_lock());
|
||||
while(!m.try_lock())
|
||||
;
|
||||
time_point t1 = Clock::now();
|
||||
assert(m.try_lock());
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(200)); // within 200ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// template <class Rep, class Period>
|
||||
// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::recursive_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
assert(m.try_lock());
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ns(50000000)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_for(ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ns(50000000)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// UNSUPPORTED: libcpp-has-no-threads
|
||||
|
||||
// <mutex>
|
||||
|
||||
// class recursive_timed_mutex;
|
||||
|
||||
// template <class Clock, class Duration>
|
||||
// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
std::recursive_timed_mutex m;
|
||||
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef std::chrono::milliseconds ms;
|
||||
typedef std::chrono::nanoseconds ns;
|
||||
|
||||
void f1()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(300)) == true);
|
||||
time_point t1 = Clock::now();
|
||||
assert(m.try_lock());
|
||||
m.unlock();
|
||||
m.unlock();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
assert(m.try_lock_until(Clock::now() + ms(250)) == false);
|
||||
time_point t1 = Clock::now();
|
||||
ns d = t1 - t0 - ms(250);
|
||||
assert(d < ms(50)); // within 50ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f1);
|
||||
std::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
{
|
||||
m.lock();
|
||||
std::thread t(f2);
|
||||
std::this_thread::sleep_for(ms(300));
|
||||
m.unlock();
|
||||
t.join();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user