1
1

- Protect callers of opal/ompi_condition_wait from spurious wakeups,

possible when with building with pthreads.
   Compiled on Linux ia32 with and without
   --enable-progress-threads

This commit was SVN r8682.
Этот коммит содержится в:
Rainer Keller 2006-01-12 17:13:08 +00:00
родитель c0bad339af
Коммит 95f886b6ab
6 изменённых файлов: 53 добавлений и 41 удалений

Просмотреть файл

@ -126,22 +126,23 @@ OMPI_DECLSPEC int ompi_free_list_grow(ompi_free_list_t* flist, size_t num_elemen
*/ */
#define OMPI_FREE_LIST_WAIT(fl, item, rc) \ #define OMPI_FREE_LIST_WAIT(fl, item, rc) \
{ \ { \
OPAL_THREAD_LOCK(&((fl)->fl_lock)); \ OPAL_THREAD_LOCK(&((fl)->fl_lock)); \
item = opal_list_remove_first(&((fl)->super)); \ item = opal_list_remove_first(&((fl)->super)); \
while(NULL == item) { \ while(NULL == item) { \
if((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) { \ if((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) { \
(fl)->fl_num_waiting++; \ (fl)->fl_num_waiting++; \
opal_condition_wait(&((fl)->fl_condition), &((fl)->fl_lock)); \ while ((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) \
(fl)->fl_num_waiting--; \ opal_condition_wait(&((fl)->fl_condition), &((fl)->fl_lock)); \
} else { \ (fl)->fl_num_waiting--; \
ompi_free_list_grow((fl), (fl)->fl_num_per_alloc); \ } else { \
} \ ompi_free_list_grow((fl), (fl)->fl_num_per_alloc); \
item = opal_list_remove_first(&((fl)->super)); \ } \
} \ item = opal_list_remove_first(&((fl)->super)); \
OPAL_THREAD_UNLOCK(&((fl)->fl_lock)); \ } \
rc = (NULL == item) ? OMPI_ERR_OUT_OF_RESOURCE : OMPI_SUCCESS; \ OPAL_THREAD_UNLOCK(&((fl)->fl_lock)); \
rc = (NULL == item) ? OMPI_ERR_OUT_OF_RESOURCE : OMPI_SUCCESS; \
} }

Просмотреть файл

@ -66,7 +66,10 @@ int ompi_request_wait_any(
/* give up and sleep until completion */ /* give up and sleep until completion */
OPAL_THREAD_LOCK(&ompi_request_lock); OPAL_THREAD_LOCK(&ompi_request_lock);
ompi_request_waiting++; ompi_request_waiting++;
do { /*
* We will break out of while{} as soon as all requests have completed.
*/
while (1) {
rptr = requests; rptr = requests;
num_requests_null_inactive = 0; num_requests_null_inactive = 0;
for (i = 0; i < count; i++, rptr++) { for (i = 0; i < count; i++, rptr++) {
@ -87,10 +90,10 @@ int ompi_request_wait_any(
} }
if(num_requests_null_inactive == count) if(num_requests_null_inactive == count)
break; break;
if (completed < 0) { while (completed < 0) {
opal_condition_wait(&ompi_request_cond, &ompi_request_lock); opal_condition_wait(&ompi_request_cond, &ompi_request_lock);
} }
} while (completed < 0); }
ompi_request_waiting--; ompi_request_waiting--;
OPAL_THREAD_UNLOCK(&ompi_request_lock); OPAL_THREAD_UNLOCK(&ompi_request_lock);

Просмотреть файл

@ -122,22 +122,23 @@ OMPI_DECLSPEC int opal_free_list_grow(opal_free_list_t* flist, size_t num_elemen
*/ */
#define OPAL_FREE_LIST_WAIT(fl, item, rc) \ #define OPAL_FREE_LIST_WAIT(fl, item, rc) \
{ \ { \
OPAL_THREAD_LOCK(&((fl)->fl_lock)); \ OPAL_THREAD_LOCK(&((fl)->fl_lock)); \
item = opal_list_remove_first(&((fl)->super)); \ item = opal_list_remove_first(&((fl)->super)); \
while(NULL == item) { \ while(NULL == item) { \
if((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) { \ if((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) { \
(fl)->fl_num_waiting++; \ (fl)->fl_num_waiting++; \
opal_condition_wait(&((fl)->fl_condition), &((fl)->fl_lock)); \ while ((fl)->fl_max_to_alloc <= (fl)->fl_num_allocated) \
(fl)->fl_num_waiting--; \ opal_condition_wait(&((fl)->fl_condition), &((fl)->fl_lock)); \
} else { \ (fl)->fl_num_waiting--; \
opal_free_list_grow((fl), (fl)->fl_num_per_alloc); \ } else { \
} \ opal_free_list_grow((fl), (fl)->fl_num_per_alloc); \
item = opal_list_remove_first(&((fl)->super)); \ } \
} \ item = opal_list_remove_first(&((fl)->super)); \
OPAL_THREAD_UNLOCK(&((fl)->fl_lock)); \ } \
rc = (NULL == item) ? OMPI_ERR_OUT_OF_RESOURCE : OMPI_SUCCESS; \ OPAL_THREAD_UNLOCK(&((fl)->fl_lock)); \
rc = (NULL == item) ? OMPI_ERR_OUT_OF_RESOURCE : OMPI_SUCCESS; \
} }

Просмотреть файл

@ -51,9 +51,12 @@ int orte_gpr_proxy_begin_compound_cmd(void)
OPAL_THREAD_LOCK(&orte_gpr_proxy_globals.wait_for_compound_mutex); OPAL_THREAD_LOCK(&orte_gpr_proxy_globals.wait_for_compound_mutex);
if (orte_gpr_proxy_globals.compound_cmd_mode) { if (orte_gpr_proxy_globals.compound_cmd_mode) {
orte_gpr_proxy_globals.compound_cmd_waiting++; orte_gpr_proxy_globals.compound_cmd_waiting++;
opal_condition_wait(&orte_gpr_proxy_globals.compound_cmd_condition, &orte_gpr_proxy_globals.wait_for_compound_mutex); while (orte_gpr_proxy_globals.compound_cmd_mode) {
orte_gpr_proxy_globals.compound_cmd_waiting--; opal_condition_wait(&orte_gpr_proxy_globals.compound_cmd_condition,
&orte_gpr_proxy_globals.wait_for_compound_mutex);
}
orte_gpr_proxy_globals.compound_cmd_waiting--;
} }
orte_gpr_proxy_globals.compound_cmd_mode = true; orte_gpr_proxy_globals.compound_cmd_mode = true;

Просмотреть файл

@ -105,7 +105,10 @@ int orte_iof_base_flush(void)
} }
if(pending != 0) { if(pending != 0) {
if(opal_event_progress_thread() == false) { if(opal_event_progress_thread() == false) {
opal_condition_wait(&orte_iof_base.iof_condition, &orte_iof_base.iof_lock); while (opal_event_progress_thread() == false) {
opal_condition_wait(&orte_iof_base.iof_condition,
&orte_iof_base.iof_lock);
}
} else { } else {
OPAL_THREAD_UNLOCK(&orte_iof_base.iof_lock); OPAL_THREAD_UNLOCK(&orte_iof_base.iof_lock);
opal_event_loop(OPAL_EVLOOP_ONCE); opal_event_loop(OPAL_EVLOOP_ONCE);

Просмотреть файл

@ -889,9 +889,10 @@ int orte_pls_rsh_launch(orte_jobid_t jobid)
rsh_daemon_info_t *daemon_info; rsh_daemon_info_t *daemon_info;
OPAL_THREAD_LOCK(&mca_pls_rsh_component.lock); OPAL_THREAD_LOCK(&mca_pls_rsh_component.lock);
if (mca_pls_rsh_component.num_children++ >= while (mca_pls_rsh_component.num_children++ >=
mca_pls_rsh_component.num_concurrent) { mca_pls_rsh_component.num_concurrent) {
opal_condition_wait(&mca_pls_rsh_component.cond, &mca_pls_rsh_component.lock); opal_condition_wait(&mca_pls_rsh_component.cond,
&mca_pls_rsh_component.lock);
} }
OPAL_THREAD_UNLOCK(&mca_pls_rsh_component.lock); OPAL_THREAD_UNLOCK(&mca_pls_rsh_component.lock);