Created
September 21, 2012 15:03
-
-
Save yifu/3762015 to your computer and use it in GitHub Desktop.
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 <iostream> | |
| #include <time.h> | |
| #include <unistd.h> | |
| #include <pthread.h> | |
| #include <sched.h> | |
| #include <errno.h> | |
| int main() | |
| { | |
| std::cout << "hello" << std::endl; | |
| //pthread_attr_t attr; | |
| //pthread_attr_init(&attr); | |
| // const int result = pthread_attr_setschedpolicy(&attr, SCHED_FIFO); | |
| struct sched_param my_param; | |
| my_param.__sched_priority = 20; | |
| errno = 0; | |
| const int result = sched_setscheduler(0/*pid*/, SCHED_FIFO, &my_param); | |
| if (result != 0) | |
| { | |
| perror("setting sched priority failed"); | |
| exit(0); | |
| } | |
| clock_t start; | |
| start = clock(); | |
| clock_t end = start + 10 * CLOCKS_PER_SEC; | |
| while(clock() < end) | |
| { | |
| int i = 0; | |
| while(i < 10000) | |
| ++i; | |
| } | |
| std::cout << "bye" << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment