Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
threadpool01
//Title of this code #include <iostream> #include <thread> #include <list> #include <mutex> using namespace std; class Job { public: virtual void work() = 0; }; class ThreadPool { int numThreads; list<thread*> workingThreads; list<thread*> freeThreads; queue<Job*> jobs; mutex jobsLock; public: ThreadPool(int threads): numThreads(threads) {} ~ThreadPool() {} void initialize() { for (int i = 0; i < numThreads; ++i) { freeThreads.push_back(new thread()); } } void addJob(Job* j) { jobsLock.lock(); jobs.push(j); jobsLock.unlock(); } void jobWrapper() private: Job* getJob() { Job* j = NULL; jobsLock.lock(); if (!jobs.empty()) { j = jobs.front(); jobs.pop(); } jobsLock.unlock(); return j; } }; int main() { std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
Good pairs
linkage
Interest Compounding
triangle_ isosceles
Maximum product subarray
Subarray with 0 sum
Some-stuff
BubbleDouble
lab17feb22x4B.cpp
Treap for spoj : MEANARR (we can use policy based data structures instead)