Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT 0x0400
- #include <windows.h>
- #include <stdio.h>
- #include <string>
- #include <iostream>
- #include <thread>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <mutex>
- #define _SECOND 2000000
- std::mutex bruh1;
- void bruh(int timeout)
- {
- srand(GetCurrentThreadId()^time(NULL));
- int timeSeconds = rand() % 10;
- HANDLE wTimer;
- __int64 endTime;
- LARGE_INTEGER quitTime;
- SYSTEMTIME now;
- wTimer = CreateWaitableTimer(NULL, FALSE, NULL);
- endTime = -5 * _SECOND*timeSeconds;
- quitTime.LowPart = (DWORD)(endTime & 0xFFFFFFFF);
- quitTime.HighPart = (LONG)(endTime >> 32);
- SetWaitableTimer(wTimer, &quitTime, 0, NULL, NULL, FALSE);
- GetSystemTime(&now);
- WaitForSingleObject(wTimer, _SECOND*-5*timeout);
- CloseHandle(wTimer);
- std::lock_guard<std::mutex> bruh2(bruh1);
- std::cout << "I died " << timeSeconds << " after"<<std::endl;
- }
- int main(int argc, char* argv[])
- {
- srand((unsigned int)time(NULL));
- int threads = 0;
- int timeout = 0;
- if (argc != 3)
- {
- std::cerr << "2 argument required";
- return 2;
- }
- else
- {
- threads = std::stoi(argv[1]);
- timeout = std::stoi(argv[2]);
- }
- for (size_t i = 0; i < threads; i++)
- {
- std::thread a(bruh,timeout);
- a.detach();
- }
- while (true)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement