diff --git a/include/villas/shmem.h b/include/villas/shmem.h index 5811eb2b0..93da15a72 100644 --- a/include/villas/shmem.h +++ b/include/villas/shmem.h @@ -19,6 +19,8 @@ struct shmem_shared { union shmem_queue out; /**< Queue for samples passed from node to external program.*/ int cond_out; /**< Whether to use a pthread_cond_t to signal if new samples are written to outqueue. */ struct pool pool; /**< Pool for the samples in the queues. */ + pthread_barrier_t start_bar; + pthread_barrierattr_t start_attr; atomic_size_t node_stopped; atomic_size_t ext_stopped; }; diff --git a/lib/nodes/shmem.c b/lib/nodes/shmem.c index e2f5435c3..9246608cf 100644 --- a/lib/nodes/shmem.c +++ b/lib/nodes/shmem.c @@ -89,8 +89,14 @@ int shmem_open(struct node *n) { if (pool_init(&shm->shared->pool, shm->insize+shm->outsize, SAMPLE_LEN(shm->sample_size), shm->manager) < 0) error("Shm pool allocation failed (not enough memory?)"); + pthread_barrierattr_init(&shm->shared->start_attr); + pthread_barrierattr_setpshared(&shm->shared->start_attr, PTHREAD_PROCESS_SHARED); + pthread_barrier_init(&shm->shared->start_bar, &shm->shared->start_attr, 2); + if (shm->exec && !spawn(shm->exec[0], shm->exec)) serror("Failed to spawn external program"); + + pthread_barrier_wait(&shm->shared->start_bar); return 0; } diff --git a/lib/shmem.c b/lib/shmem.c index 7feab1ff9..70c491f0c 100644 --- a/lib/shmem.c +++ b/lib/shmem.c @@ -49,7 +49,9 @@ struct shmem_shared* shmem_shared_open(const char *name, void **base_ptr) cptr = (char *) base + sizeof(struct memtype) + sizeof(struct memblock); if (base_ptr) *base_ptr = base; - return (struct shmem_shared *) cptr; + shm = (struct shmem_shared *) cptr; + pthread_barrier_wait(&shm->start_bar); + return shm; } int shmem_shared_close(struct shmem_shared *shm, void *base)