Created
February 7, 2016 20:59
-
-
Save travispaul/662ea28076418f653b94 to your computer and use it in GitHub Desktop.
pthread test
This file contains hidden or 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> | |
#include <assert.h> | |
#include <unistd.h> | |
#include <errno.h> | |
void *perform_work(void *argument) | |
{ | |
int passed_in_value; | |
passed_in_value = *((int *) argument); | |
printf("Hello World! It's me, thread with argument %d!\n", passed_in_value); | |
sleep(1); | |
} | |
int main(void) | |
{ | |
pthread_t thread; | |
int thread_arg = 1; | |
int result_code; | |
struct sched_param param; | |
int policy = 0; | |
result_code = pthread_create(&thread, NULL, perform_work, (void *) &thread_arg); | |
assert(0 == result_code); | |
policy = SCHED_FIFO; | |
result_code = pthread_setschedparam(thread, policy, ¶m); | |
perror(NULL); | |
fprintf(stderr, "result_code: %i, policy: %i\n", result_code, policy); | |
fprintf(stderr, "EINVAL=%i, ENOTSUP=%i, ESRCH=%i\n", EINVAL, ENOTSUP, ESRCH); | |
assert(0 == result_code); | |
result_code = pthread_join(thread, NULL); | |
assert(0 == result_code); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As unprivileged user:
SCHED_FIFO
SCHED_RR
SCHED_OTHER
As root:
SCHED_FIFO (success)
SCHED_RR (success)
SCHED_OTHER