-
-
Save scottjacksonx/551282 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
float actual_usage(pth_t thread) | |
{ | |
float p_run_time = (float)clock() / 100000; | |
long t_run_time = thread->running.tv_sec; | |
return (t_run_time/p_run_time) * 100; | |
} | |
float target_usage() | |
{ | |
return 100/(pth_ctrl(PTH_CTRL_GETTHREADS_NEW) + 1); | |
} | |
void assign_tickets(pth_t thread) | |
{ | |
int error = target_usage() - actual_usage(thread); | |
int numTickets = error + 100; | |
printf("Thread is at %d\n", numTickets); | |
} | |
void *thread_func(void* s) | |
{ | |
while (1) { | |
printf("asdf\n"); | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
pth_init(); | |
for (int i = 0; i < 10; i++) { | |
pth_t th = pth_spawn(PTH_ATTR_DEFAULT, thread_func, NULL); | |
}/* | |
pth_t th = pth_spawn(PTH_ATTR_DEFAULT, NULL, NULL); | |
while(1) { | |
printf("usage: %f\n", actual_usage(th)); | |
}*/ | |
printf("expected usage: %f\n", target_usage()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment