Skip to content

Instantly share code, notes, and snippets.

@larsch
Created March 7, 2015 18:55
Show Gist options
  • Save larsch/58d1be84b24c98a4493f to your computer and use it in GitHub Desktop.
Save larsch/58d1be84b24c98a4493f to your computer and use it in GitHub Desktop.
#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, &param));
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