aboutsummaryrefslogtreecommitdiff
path: root/src/im-sandbox.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-07-13 16:19:30 +0200
committerThomas White <taw@physics.org>2015-07-13 16:19:30 +0200
commit4612f7dc43f5341cc0c0b5dc52e74d7cdaedba86 (patch)
tree01c6cfaa15a6241dc6be06afad50f4c6ff0ccf7d /src/im-sandbox.c
parentfc2a630ffa41f34454911c3a91c253b82475212c (diff)
Fix racy queue filling
Diffstat (limited to 'src/im-sandbox.c')
-rw-r--r--src/im-sandbox.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index 1264c46a..cd66c728 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -787,6 +787,7 @@ void create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
char semname_q[64];
struct sigaction sa;
int r;
+ int no_more = 0;
int allDone = 0;
if ( n_proc > MAX_NUM_WORKERS ) {
@@ -920,8 +921,9 @@ void create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
/* Top up the queue if necessary */
pthread_mutex_lock(&sb->shared->queue_lock);
- if ( sb->shared->n_events < QUEUE_SIZE/2 ) {
- fill_queue(fh, config_basename, iargs->det, prefix, sb);
+ if ( !no_more && (sb->shared->n_events < QUEUE_SIZE/2) ) {
+ if ( fill_queue(fh, config_basename, iargs->det,
+ prefix, sb) ) no_more = 1;
}
pthread_mutex_unlock(&sb->shared->queue_lock);
@@ -931,7 +933,7 @@ void create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
/* Have all the events been swallowed? */
pthread_mutex_lock(&sb->shared->queue_lock);
- if ( sb->shared->n_events == 0 ) allDone = 1;
+ if ( no_more && (sb->shared->n_events == 0) ) allDone = 1;
pthread_mutex_unlock(&sb->shared->queue_lock);
} while ( !allDone );