Specifying t secs to wait added

This commit is contained in:
pithikos 2015-02-06 10:54:22 +00:00
parent c03e2ee059
commit 8098f92c8c

View File

@ -8,36 +8,38 @@
/*
* This program takes 3 arguments: number of jobs to add,
* number of threads,
* wait for each thread (1) or all threads at once (0)?
* wait for each thread separetely (1)?
* how long each thread should run
*
* Each job is to simply sleep for one second.
* Each job is to simply sleep for given amount of seconds.
*
* */
void sleep_1() {
sleep(1);
void sleep_1(int* secs) {
sleep(*secs);
}
int main(int argc, char *argv[]){
char* p;
if (argc != 4){
puts("This testfile needs excactly three arguments");
if (argc < 3){
puts("This testfile needs at least two arguments");
exit(1);
}
int num_jobs = strtol(argv[1], &p, 10);
int num_threads = strtol(argv[2], &p, 10);
int wait_each_job = strtol(argv[3], &p, 10);
int num_jobs = strtol(argv[1], &p, 10);
int num_threads = strtol(argv[2], &p, 10);
int wait_each_job = argv[3] ? strtol(argv[3], &p, 10) : 0;
int sleep_per_thread = argv[4] ? strtol(argv[4], &p, 10) : 1;
threadpool thpool = thpool_init(num_threads);
int n;
for (n=0; n<num_jobs; n++){
thpool_add_work(thpool, (void*)sleep_1, NULL);
thpool_add_work(thpool, (void*)sleep_1, &sleep_per_thread);
if (wait_each_job)
thpool_wait(thpool);
}