Given the following bit of code, I was wondering what the equivalent bit of code would be in linux assuming pthreads or even using the Boost.Thread API.
#inc
For those who may be searching for BSD based OS solutions such as MacOS or iOS, you may want to consider setting the thread's priority using mach instead of the POSIX equivalent if necessary.
#include
#include
#include
#include
int set_realtime(int period, int computation, int constraint) {
struct thread_time_constraint_policy ttcpolicy;
int ret;
thread_port_t threadport = pthread_mach_thread_np(pthread_self());
ttcpolicy.period=period; // HZ/160
ttcpolicy.computation=computation; // HZ/3300;
ttcpolicy.constraint=constraint; // HZ/2200;
ttcpolicy.preemptible=1;
if ((ret=thread_policy_set(threadport,
THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&ttcpolicy,
THREAD_TIME_CONSTRAINT_POLICY_COUNT)) != KERN_SUCCESS) {
fprintf(stderr, "set_realtime() failed.\n");
return 0;
}
return 1;
}
Source: https://developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html