Commit 99485af8 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

Thread critical-section initialization fixes.



This patch has two related parts.

1. We initialize the isThreaded runtime check to FALSE before doing
the cvar checks.  This is because the cvar initialization uses memory
allocation and string duping, which internally use mutexes.  But the
mutexes are not initialized yet, so disabling isThreaded would make
sure we don't use them.

2. Updates to the pamid device to respect the isThreaded variable.

This is needed since we were initializing cvars before setting the
thread-level, so the thread-safety macros are not initialized at that
point.  See #1900.
Signed-off-by: default avatarMichael Blocksome <blocksom@us.ibm.com>
Signed-off-by: Rob Latham's avatarRob Latham <robl@mcs.anl.gov>
parent 3b24d318
......@@ -142,6 +142,17 @@ int MPI_Init( int *argc, char ***argv )
/* ... body of routine ... */
/* Temporarily disable thread-safety. This is needed because the
* mutexes are not initialized yet, and we don't want to
* accidentally use them before they are initialized. We will
* reset this value once it is properly initialized. */
/* FIXME: This only works when runtime thread-safety is enabled.
* When we use configure-time thread-levels, we might still have a
* problem. */
#ifdef HAVE_RUNTIME_THREADCHECK
MPIR_ThreadInfo.isThreaded = 0;
#endif
MPIR_T_env_init();
if (!strcmp(MPIR_CVAR_DEFAULT_THREAD_LEVEL, "MPI_THREAD_MULTIPLE"))
......
......@@ -614,6 +614,17 @@ int MPI_Init_thread( int *argc, char ***argv, int required, int *provided )
/* ... body of routine ... */
/* Temporarily disable thread-safety. This is needed because the
* mutexes are not initialized yet, and we don't want to
* accidentally use them before they are initialized. We will
* reset this value once it is properly initialized. */
/* FIXME: This only works when runtime thread-safety is enabled.
* When we use configure-time thread-levels, we might still have a
* problem. */
#ifdef HAVE_RUNTIME_THREADCHECK
MPIR_ThreadInfo.isThreaded = 0;
#endif
MPIR_T_env_init();
/* If the user requested for asynchronous progress, request for
......
......@@ -50,7 +50,6 @@
#error Need HAVE_RUNTIME_THREADCHECK
#endif
#define MPIU_THREAD_CS_INIT ({ MPIDI_Mutex_initialize(); })
#define MPIU_THREAD_CS_FINALIZE
......@@ -111,19 +110,55 @@
#elif MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_PER_OBJECT
#define MPIDI_CS_ENTER(m) ({ MPIDI_Mutex_acquire(m); })
#define MPIDI_CS_EXIT(m) ({ MPIDI_Mutex_sync(); MPIDI_Mutex_release(m); })
#define MPIDI_CS_YIELD(m) ({ MPIDI_Mutex_sync(); MPIDI_Mutex_release(m); MPIDI_Mutex_acquire(m); })
#define MPIDI_CS_TRY(m) ({ (0==MPIDI_Mutex_try_acquire(m)); })
#define MPIDI_CS_SCHED_YIELD(m) ({ MPIDI_Mutex_sync(); MPIDI_Mutex_release(m); sched_yield(); MPIDI_Mutex_acquire(m); })
#define MPIDI_CS_ENTER(m) \
do { \
MPIU_THREAD_CHECK_BEGIN \
MPIDI_Mutex_acquire(m); \
MPIU_THREAD_CHECK_END \
} while (0)
#define MPIDI_CS_EXIT(m) \
do { \
MPIU_THREAD_CHECK_BEGIN \
MPIDI_Mutex_sync(); \
MPIDI_Mutex_release(m); \
MPIU_THREAD_CHECK_END \
} while (0)
#define MPIDI_CS_YIELD(m) \
do { \
MPIU_THREAD_CHECK_BEGIN \
MPIDI_Mutex_sync(); \
MPIDI_Mutex_release(m); \
MPIDI_Mutex_acquire(m); \
MPIU_THREAD_CHECK_END \
} while (0)
#define MPIDI_CS_TRY(m) \
do { \
MPIU_THREAD_CHECK_BEGIN \
MPIDI_Mutex_try_acquire(m); \
MPIU_THREAD_CHECK_END \
} while (0)
#define MPIDI_CS_SCHED_YIELD(m) \
do { \
MPIU_THREAD_CHECK_BEGIN \
MPIDI_Mutex_sync(); \
MPIDI_Mutex_release(m); \
sched_yield(); \
MPIDI_Mutex_acquire(m); \
MPIU_THREAD_CHECK_END \
} while (0)
#define MPIU_THREAD_CS_ALLFUNC_ENTER(_context)
#define MPIU_THREAD_CS_ALLFUNC_EXIT(_context)
#define MPIU_THREAD_CS_ALLFUNC_YIELD(_context)
#define MPIU_THREAD_CS_ALLFUNC_SCHED_YIELD(_context)
#define MPIU_THREAD_CS_ALLFUNC_TRY(_context) (0)
#define MPIU_THREAD_CS_INIT_ENTER(_context) MPIDI_Mutex_acquire(0)
#define MPIU_THREAD_CS_INIT_EXIT(_context) MPIDI_Mutex_release(0)
#define MPIU_THREAD_CS_INIT_ENTER(_context) MPIDI_CS_ENTER(0)
#define MPIU_THREAD_CS_INIT_EXIT(_context) MPIDI_CS_EXIT(0)
#define MPIU_THREAD_CS_CONTEXTID_ENTER(_context) MPIDI_CS_ENTER(0)
#define MPIU_THREAD_CS_CONTEXTID_EXIT(_context) MPIDI_CS_EXIT (0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment