@@ -60,7 +60,7 @@ static int iterations = 0;
atomic_t step;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-pthread_mutex_t mutex;
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int ret = 0;
@@ -68,7 +68,7 @@ int over_30 = 0;
atomic_t step;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-pthread_mutex_t mutex;
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void usage(void)
{
@@ -74,7 +74,7 @@ int gettid(void)
}
typedef void *(*entrypoint_t) (void *);
-pthread_mutex_t glob_mutex;
+pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
@@ -76,7 +76,7 @@ int gettid(void)
}
typedef void *(*entrypoint_t) (void *);
-pthread_mutex_t glob_mutex;
+pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
@@ -75,7 +75,7 @@ int gettid(void)
}
typedef void *(*entrypoint_t) (void *);
-pthread_mutex_t *glob_mutex;
+pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
@@ -86,7 +86,7 @@ void *func_nonrt(void *arg)
printf("Thread %d started running with priority %d\n", tid,
pthr->priority);
- pthread_mutex_lock(glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
tid, pthr->policy, pthr->priority);
@@ -106,7 +106,7 @@ void *func_nonrt(void *arg)
}
busy_work_ms(1);
}
- pthread_mutex_unlock(glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return NULL;
}
@@ -117,7 +117,7 @@ void *func_rt(void *arg)
printf("Thread %d started running with prio %d\n", tid, pthr->priority);
pthread_barrier_wait(&barrier);
- pthread_mutex_lock(glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
tid, pthr->policy, pthr->priority);
@@ -134,7 +134,7 @@ void *func_rt(void *arg)
}
busy_work_ms(1);
}
- pthread_mutex_unlock(glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return NULL;
}
@@ -198,14 +198,8 @@ int main(int argc, char *argv[])
printf("Start %s\n", argv[0]);
- glob_mutex = malloc(sizeof(pthread_mutex_t));
- if (glob_mutex == NULL) {
- printf("Malloc failed\n");
- exit(errno);
- }
-
if (!nopi)
- init_pi_mutex(glob_mutex);
+ init_pi_mutex(&glob_mutex);
create_other_thread(func_nonrt, NULL);
create_rr_thread(func_rt, NULL, 20);
@@ -217,7 +211,7 @@ int main(int argc, char *argv[])
join_threads();
printf("Done\n");
- pthread_mutex_destroy(glob_mutex);
+ pthread_mutex_destroy(&glob_mutex);
pthread_mutex_destroy(&cond_mutex);
pthread_cond_destroy(&cond_var);
@@ -55,7 +55,7 @@ static int use_flag_mutex;
static int max_delay_us;
static int max_drop2grab_us;
-static pthread_mutex_t pi_mutex;
+static pthread_mutex_t pi_mutex = PTHREAD_MUTEX_INITIALIZER;
// flagging details
typedef enum {
@@ -69,7 +69,7 @@ typedef enum {
static volatile phase_t phase_flag = END_OF_CYCLE;
-static pthread_mutex_t flag_mutex;
+static pthread_mutex_t flag_mutex = PTHREAD_MUTEX_INITIALIZER;
int med_threads = 0;
long iterations = ITERATIONS;
@@ -63,7 +63,7 @@
#define THRESHOLD 200 /* microseconds */
pthread_barrier_t bar1, bar2;
-pthread_mutex_t lock;
+pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static int end = 0;
@@ -60,7 +60,7 @@ volatile int running_threads = 0;
static int rt_threads = 0;
static int locked_broadcast = 1;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t mutex;
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static volatile nsec_t beginrun;
static int ret = 0;
@@ -47,7 +47,7 @@
#include <librttest.h>
#include <libstats.h>
#define PASS_US 100
-pthread_mutex_t child_mutex;
+pthread_mutex_t child_mutex = PTHREAD_MUTEX_INITIALIZER;
volatile int *child_waiting = NULL;
double endtime;
pthread_cond_t *condlist = NULL;
@@ -39,9 +39,9 @@
#define NUM_SLAVES 20
#define SLAVE_PRIO 89
-pthread_mutex_t MM;
-pthread_mutex_t MS;
-pthread_mutex_t MT;
+pthread_mutex_t MM = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t MS = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t MT = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t CM;
pthread_cond_t CS;
pthread_cond_t CT;