boost variant
http://habrahabr.ru/post/270689/
Код: Выделить всё
dumpbin.exe /EXPORTS /rawdata:none "путь-к-dll" >> "файл-куда-записать-инфу"
Код: Выделить всё
YAH - return int, YAX - return void
PA + <литера числа> = указатель на него
D - char, E - uchar, F - short, (G - ushort,) H - int, I - uint, J - long, K = ulong, _J - int64, _K - uint64, ( L - int128,) _N - bool
M - float, N - double, O - long double, (X - void,) _W - wchar_t
Код: Выделить всё
#include <iostream>
#include <thread>
#include <atomic>
#include <condition_variable>
#include <mutex>
class barrier {
const unsigned int threadCount;
std::atomic<unsigned int>threadsWaiting;
bool isNotWaiting;
std::condition_variable waitVariable;
std::mutex mutex;
public:
barrier(unsigned int n) : threadCount(n) {
threadsWaiting = 0;
isNotWaiting = false;
}
barrier(const barrier &) = delete;
void wait() {
if (threadsWaiting.fetch_add(1) >= threadCount - 1) {
isNotWaiting = true;
waitVariable.notify_all();
threadsWaiting.store(0);
}
else {
std::unique_lock<std::mutex> lock(mutex);
waitVariable.wait(lock,[&]{ return isNotWaiting;});
}
}
};
barrier *myBarrier;
class Thread {
private:
std::thread* cppthread;
static void threadFunction(Thread* arg) {
arg->run();
}
public:
Thread() {}
Thread(const Thread&) = delete;
virtual ~Thread() {delete cppthread;}
virtual void run() = 0;
void start() {
cppthread = new std::thread(Thread::threadFunction, this);
}
void wait() {
cppthread->join();
}
};
class BarrierDemo: public Thread {
int id;
public:
BarrierDemo(int i) {
id = i;
}
void run() {
std::cout << "Thread " << id << "runs before barrier" << std::endl;
myBarrier->wait();
std::cout << "Thread " << id << "runs after barrier" << std::endl;
}
};
int main() {
// your code goes here
int threads;
std::cin >> threads;
myBarrier = new barrier(threads);
BarrierDemo* bardemos = static_cast<BarrierDemo*>(::operator new(sizeof(BarrierDemo)*threads));
for (int i = 0; i < threads; i++) {
new (&bardemos[i])BarrierDemo(i);
bardemos[i].start();
}
for (int i = 0; i < threads; i++) {
bardemos[i].wait();
}
::operator delete(bardemos);
delete myBarrier;
return 0;
}
Вернуться в «Программирование (под Desktop и Android)»
Сейчас этот раздел просматривают: 12 гостей