Skip to content

Commit

Permalink
Added cancellation points to worker
Browse files Browse the repository at this point in the history
This is to start addressing #12
  • Loading branch information
programagor committed Sep 25, 2018
1 parent 41f564c commit 9b8a8dc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ void* worker(void *arg_v)
}



pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
/* Run until number of runs is reached */
while(1)
{

/* Generate a point that is outside of set */
long double complex c,Z;
int8_t inside; /* 0 is no, 1 is yes, -1 is maybe */
Expand All @@ -62,6 +61,7 @@ void* worker(void *arg_v)

int U1,U2;
/* rand is not thread safe, needs locking */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_mutex_lock(arg->lock_rand);
do
{
Expand All @@ -71,6 +71,7 @@ void* worker(void *arg_v)
U2=rand();
run=++*(arg->counter);
pthread_mutex_unlock(arg->lock_rand);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
if(run>=arg->runs)
{
/* We're done, quitting thread */
Expand Down Expand Up @@ -98,11 +99,11 @@ void* worker(void *arg_v)

inside=preiterator(c,arg->function,arg->optimiser,arg->iter[0],arg->iter[l],arg->bail);

pthread_testcancel();

}
while(inside==1);


int64_t idx_x,idx_y; /* buff (2D array) coords */

/* Now we have a point which is outside, can iterate and draw */
Expand All @@ -128,6 +129,7 @@ void* worker(void *arg_v)
/* Which buffer does this go to? */
uint32_t k;
for(k=0;i>arg->iter[k+1] && k<l-1;k++);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_mutex_lock(&arg->locks[k]);
arg->hits[k]++;
for(uint32_t x=0;x< arg->re_size;x++)
Expand All @@ -144,6 +146,7 @@ void* worker(void *arg_v)
}
}
pthread_mutex_unlock(&arg->locks[k]);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

for(uint32_t x=0;x< arg->re_size;x++)
{
Expand Down

0 comments on commit 9b8a8dc

Please sign in to comment.