#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <thread> // std::this_thread::sleep_for
#include <chrono>
#include <iostream>
// std::mutex m1;
// std::mutex m2;
void* function( void* arg )
{
printf( "This is thread %ld\n", pthread_self() );
return( 0 );
}
int main( void )
{
pthread_attr_t attr;
pthread_attr_init( &attr );
pthread_attr_setdetachstate(
&attr, PTHREAD_CREATE_DETACHED );
pthread_t thread;
pthread_create( &thread, &attr, &function, NULL );
int policy = SCHED_FIFO; ;
int const min_value{ sched_get_priority_min(policy) };
std::cout << "Min prio:" << min_value << '\n';
int const max_value{ sched_get_priority_max(policy) };
std::cout << "Max prio:" << max_value << '\n';
sched_param sch;
pthread_getschedparam(thread, &policy, &sch);
sch.sched_priority = 20;
if (pthread_setschedparam(thread, policy, &sch)) {
std::cout << "Failed to setschedparam: " << '\n';
}
std::cout << "Policy: " << policy << '\n';
/* Allow threads to run for 60 seconds. */
//sleep( 60 );
std::chrono::microseconds(200000);
return EXIT_SUCCESS;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHB0aHJlYWQuaD4KI2luY2x1ZGUgPHRocmVhZD4gICAgICAgICAvLyBzdGQ6OnRoaXNfdGhyZWFkOjpzbGVlcF9mb3IKI2luY2x1ZGUgPGNocm9ubz4gCiNpbmNsdWRlIDxpb3N0cmVhbT4KCi8vIHN0ZDo6bXV0ZXggbTE7Ci8vIHN0ZDo6bXV0ZXggbTI7CiAgICAKdm9pZCogIGZ1bmN0aW9uKCB2b2lkKiAgYXJnICkKewogICBwcmludGYoICJUaGlzIGlzIHRocmVhZCAlbGRcbiIsIHB0aHJlYWRfc2VsZigpICk7CiAgIHJldHVybiggMCApOwp9CgppbnQgbWFpbiggdm9pZCApCnsKICAgcHRocmVhZF9hdHRyX3QgYXR0cjsKCiAgIHB0aHJlYWRfYXR0cl9pbml0KCAmYXR0ciApOwogICBwdGhyZWFkX2F0dHJfc2V0ZGV0YWNo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