Project

General

Profile

Bug #734 » race-tp-string.c

Mathieu Desnoyers, 04/16/2014 05:30 PM

 
/*
* Thread testing
*
* build with gcc -lpthread -o pthread pthread.c
*
* Mathieu Desnoyers
* License: GPL
*/

#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <urcu/compiler.h>

#define TRACEPOINT_DEFINE
#define TRACEPOINT_CREATE_PROBES
#include "ust_test.h"

static int __thread test = 0;

static char teststr[1024];

/* signal handler */
void handler(int signo)
{
printf("Sig handler : TID %lu, pid : %lu\n", pthread_self(), getpid());
}

void *thr1(void *arg)
{
test = 1;
printf("thread 1, thread id : %lu, pid %lu, test %d\n",
pthread_self(), getpid(), test);
sleep(1);
while(1) {
tracepoint(ust_test, mytp, teststr);
cmm_barrier();
}
return ((void*)1);

}

void *thr2(void *arg)
{
printf("thread 2, thread id : %lu, pid %lu, test %d\n",
pthread_self(), getpid(), test);
while(1) {
cmm_barrier();
//memset(teststr, 0, 1024);
cmm_barrier();
strcpy(teststr, "testblah");
cmm_barrier();
strcpy(teststr, "abc");
cmm_barrier();
strcpy(teststr, "abcsdfasdfasdfasdf");
cmm_barrier();
}
return ((void*)2);
}

int main()
{
int err;
pthread_t tid1, tid2;
void *tret;
static struct sigaction act;

act.sa_handler = handler;
sigemptyset(&(act.sa_mask));
sigaddset(&(act.sa_mask), SIGUSR1);
sigaction(SIGUSR1, &act, NULL);

err = pthread_create(&tid1, NULL, thr1, NULL);
if (err != 0)
exit(1);

err = pthread_create(&tid2, NULL, thr2, NULL);
if (err != 0)
exit(1);

sleep(10);

err = pthread_join(tid1, &tret);
if (err != 0)
exit(1);

err = pthread_join(tid2, &tret);
if (err != 0)
exit(1);

return 0;
}
(4-4/5)