#include"stdio.h"
#include"pthread.h"
/*
void *thr_fn(void *arg)
{
int j = 0;
for(j=0;j<1000;j++)
{
sleep(1);
printf("new thread: \n");
}
}
int main()
{
int err;
int i = 0;
pthread_t tid;
err=pthread_create(&tid,NULL,thr_fn,NULL);
if(err=0)
printf("can’t create thread:%s\n",strerror(err));
for(i=0; i<100; i++)
{
sleep(1);
printf("main thread: \n");
}
sleep(10);
*/
/*
int g_inum;
pthread_mutex_t testlock;
void *thr_fn(void *arg)
{
int j;
// pthread_mutex_lock(&testlock);
for(j=0;j<10000000;j++)
{
pthread_mutex_lock(&testlock);
g_inum++;
pthread_mutex_lock(&testlock);
}
// pthread_mutex_unlock(&testlock);
}
int main()
{
int err;
int i = 0;
pthread_t tid;
pthread_mutex_init(&testlock, NULL);
printf("Main init lock \n");
for(i=0;i<10;i++)
{
err=pthread_create(&tid,NULL,thr_fn,NULL);
if(err=0)
printf("can’t create thread:%s\n",strerror(err));
}
sleep(10);
pthread_mutex_destroy(&testlock);
printf("main destroy lock \n");
printf("the result is %d\n",g_inum);
*/
return 0;
}