Skip to content

Commit

Permalink
Lower kw thread pool thread scheduling priority
Browse files Browse the repository at this point in the history
Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian committed Aug 21, 2023
1 parent b6f01a6 commit e941068
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion thirdparty/ctpl/ctpl-std.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <exception>
#include <future>
#include <mutex>
#include <pthread.h>
#include <cstring>
#include <iostream>
#include <queue>


Expand Down Expand Up @@ -231,7 +234,19 @@ namespace ctpl {
return; // if the queue is empty and this->isDone == true or *flag then return
}
};
this->threads[i].reset(new std::thread(f)); // compiler may not support std::make_unique()
auto* t = new std::thread(f);
sched_param sch_params;
int policy = SCHED_FIFO;
sch_params.sched_priority = sched_get_priority_min(policy);
auto handle = t->native_handle();
int en = pthread_setschedparam(handle, policy, &sch_params);
if (en) {
std::cerr << "Failed to set Thread scheduling: " << std::strerror(en) << std::endl;
} else {
std::cout << "set kw thread pool thread priority to min: " << sch_params.sched_priority
<< ", max is " << sched_get_priority_max(policy) << " thread " << handle << "\n";
}
this->threads[i].reset(t); // compiler may not support std::make_unique()
}

void init() { this->nWaiting = 0; this->isStop = false; this->isDone = false; }
Expand Down

0 comments on commit e941068

Please sign in to comment.