MCPcopy Create free account
hub / github.com/Tencent/phxrpc / PluckThread

Class PluckThread

phxrpc/rpc/test_thread_queue.cpp:34–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class PluckThread {
35 public:
36 PluckThread(ThdQueue<int> * thd_queue, const size_t thread_count) :
37 thd_queue_(thd_queue) {
38 for (size_t i = 0; i < thread_count; i++) {
39 thread * thd = new thread(&PluckThread::Func, this, i);
40 thread_list_.push_back(thd);
41 }
42 }
43
44 ~PluckThread() {
45 thd_queue_->break_out();
46 for (auto & thd : thread_list_) {
47 thd->join();
48 delete thd;
49 }
50 }
51
52 void Func(size_t id) {
53 int n = 0;
54 do {
55 bool succ = thd_queue_->pluck(n);
56 if (succ) {
57 printf("thread_id(%zu) value(%d)\n", id, n);
58 } else {
59 break;
60 }
61 } while (!thd_queue_->empty());
62 }
63
64 private:
65 ThdQueue<int> * thd_queue_;
66 vector<thread *> thread_list_;
67};
68
69int main(int argc, char ** argv) {
70 ThdQueue<int> thd_queue;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected