int (*parse_arg_ext) (char *) = NULL;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-int shared_flag = 0;
+volatile int shared_flag = 0;
ts_t timestamp1, timestamp2;
int try = 0;
{
while (try < nb_measurements) {
pthread_mutex_lock (&mutex);
- shared_flag = 1;
sys_timestamp (×tamp1);
+ shared_flag = 1;
pthread_mutex_unlock (&mutex);
}
pthread_exit (NULL);
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
+#include <string.h>
#include "mtime.h"
#include "test.h"
int counter = 0;
int try = 0;
sem_t sem;
-ts_t ts1, ts2;
void* trythis (__attribute__((unused)) void *arg)
{
sem_wait (&sem);
- counter += 1;
+ static ts_t tsi;
+ ts_t ts;
+ sys_timestamp (&ts);
/* thread 1 took the lock -> timestamp 1 */
- if (counter % 2 != 0) {
- sys_timestamp (&ts1);
+ if (counter % 2 == 0) {
+ set_timestamp (&tsi, &ts);
}
/* thread 2 took the lock -> timestamp 2 */
else {
- sys_timestamp (&ts2);
- measure_tab[try++] = diff_timestamp (&ts2, &ts1);
+ measure_tab[try++] = diff_timestamp (&ts, &tsi);
}
+ counter += 1;
+
sem_post (&sem);
return NULL;
for (int i = 0; i < nb; i++) {
+ //bzero (&tsi, sizeof (ts1));
+
pthread_t tid1;
if (pthread_create (&tid1, NULL, trythis, NULL) != 0) {
fprintf (stderr, "error on pthread_create\n");