Created
March 7, 2015 18:55
-
-
Save larsch/58d1be84b24c98a4493f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
void* thread_routine(void* param) { | |
printf("I'm running\n"); | |
} | |
#define CP(x) \ | |
{ int r = (x); \ | |
if (r != 0) { printf("%s: %s (%d)\n", #x, strerror(r), r); exit(1); } } | |
int main() { | |
pthread_t thread; | |
pthread_attr_t attr; | |
struct sched_param param; | |
int r; | |
void* value; | |
param.sched_priority = 22; | |
CP(pthread_attr_init(&attr)); | |
CP(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)); | |
CP(pthread_attr_setschedpolicy(&attr, SCHED_RR)); | |
CP(pthread_attr_setschedparam(&attr, ¶m)); | |
CP(pthread_create(&thread, &attr, &thread_routine, NULL)); | |
CP(pthread_join(thread, &value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment