From 02db9b77f6cbc255a7622c54d0ccad82e0db4481 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Fri, 12 Jun 2009 00:36:31 +0200 Subject: [PATCH] Bug in communication techniques bench * prod_idx and cons_idx aren't declared volatile so compiler could sur-optimize access to these variable and lead to a deadlock --- communication_techniques/include/shared_mem_comm.h | 8 ++++---- communication_techniques/include/shared_mem_opt_comm.h | 8 ++++---- communication_techniques/src/shared_mem.c | 4 ++-- communication_techniques/src/shared_mem_opt.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/communication_techniques/include/shared_mem_comm.h b/communication_techniques/include/shared_mem_comm.h index 2d8c041..61b6cc9 100644 --- a/communication_techniques/include/shared_mem_comm.h +++ b/communication_techniques/include/shared_mem_comm.h @@ -14,8 +14,8 @@ struct communication_assoc struct communication_assoc *prev; pthread_t tid; uintptr_t *shared_space; - int *cons_idx; - int *prod_idx; + volatile int *cons_idx; + volatile int *prod_idx; }; extern struct communication_assoc assoc_root; @@ -23,8 +23,8 @@ extern struct communication_assoc assoc_root; __BEGIN_DECLS extern __thread uintptr_t *shared_space; -extern __thread int prod_idx; -extern __thread int cons_idx; +extern __thread volatile int prod_idx; +extern __thread volatile int cons_idx; struct communication_assoc *create_comm_assoc(void); static inline void send(uintptr_t value) { diff --git a/communication_techniques/include/shared_mem_opt_comm.h b/communication_techniques/include/shared_mem_opt_comm.h index ec38cc8..c518ea8 100644 --- a/communication_techniques/include/shared_mem_opt_comm.h +++ b/communication_techniques/include/shared_mem_opt_comm.h @@ -14,8 +14,8 @@ struct communication_assoc struct communication_assoc *prev; pthread_t tid; uintptr_t *shared_space; - int *cons_idx; - int *prod_idx; + volatile int *cons_idx; + volatile int *prod_idx; }; extern struct communication_assoc assoc_root; @@ -23,8 +23,8 @@ extern struct communication_assoc assoc_root; __BEGIN_DECLS extern __thread uintptr_t *shared_space; -extern __thread int prod_idx; -extern __thread int cons_idx; +extern __thread volatile int prod_idx; +extern __thread volatile int cons_idx; struct communication_assoc *create_comm_assoc(void); static inline void send(uintptr_t value) { diff --git a/communication_techniques/src/shared_mem.c b/communication_techniques/src/shared_mem.c index ac03b0d..8f624d8 100644 --- a/communication_techniques/src/shared_mem.c +++ b/communication_techniques/src/shared_mem.c @@ -9,8 +9,8 @@ __thread uintptr_t *shared_space; -__thread int cons_idx = 0; -__thread int prod_idx = 0; +__thread volatile int cons_idx = 0; +__thread volatile int prod_idx = 0; struct communication_assoc *create_comm_assoc(void) { diff --git a/communication_techniques/src/shared_mem_opt.c b/communication_techniques/src/shared_mem_opt.c index 15249f6..7b154b5 100644 --- a/communication_techniques/src/shared_mem_opt.c +++ b/communication_techniques/src/shared_mem_opt.c @@ -9,8 +9,8 @@ __thread uintptr_t *shared_space; -__thread int cons_idx = 0; -__thread int prod_idx = 0; +__thread volatile int cons_idx = 0; +__thread volatile int prod_idx = 0; struct communication_assoc *create_comm_assoc(void) {