Many of the test executables use pthreads directly. This isn't portable on Windows, so this patch converts these test to use C++11 threads and mutexes. Since Windows' implementation of std::thread classes throw and catch from header files, this patch also disables exceptions when compiling with clang on Windows. Reviewed by: Todd Fiala, Ed Maste Differential Revision: http://reviews.llvm.org/D4816 llvm-svn: 215562
32 lines
639 B
C++
32 lines
639 B
C++
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
void *start(void *data)
|
|
{
|
|
int i;
|
|
size_t idx = (size_t)data;
|
|
for (i=0; i<30; i++)
|
|
{
|
|
if ( idx == 0 )
|
|
std::this_thread::sleep_for(std::chrono::microseconds(1));
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
static const size_t nthreads = 16;
|
|
std::thread threads[nthreads];
|
|
size_t i;
|
|
|
|
for (i=0; i<nthreads; i++)
|
|
threads[i] = std::move(std::thread(start, (void*)i));
|
|
|
|
for (i=0; i<nthreads; i++)
|
|
threads[i].join();
|
|
}
|