Skip to content

Commit

Permalink
Specifying t secs to wait added
Browse files Browse the repository at this point in the history
  • Loading branch information
pithikos committed Feb 6, 2015
1 parent c03e2ee commit 8098f92
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/src/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8098f92

Please sign in to comment.