- 论坛徽章:
- 0
|
闲极无聊,为了浇灌已经荒芜的BLOG,胡乱写写代码。
/**********************************************
作者:猪头流氓
时间:Tue Dec 26 16:45:30 2006
文件名:tt.c
描述:
gcc -o target tt.c -lpthread
gcc -o target tt.c -lpthread -DLOCK
**********************************************/
#include
#include
#ifdef LOCK
pthread_mutex_t lm;
#endif
void * func(void * avg);
int count;
int main()
{
#ifdef LOCK
pthread_mutex_init(&lm, NULL);
#endif
pthread_t pa,pb;
pthread_create(&pa, NULL, &func, NULL);
pthread_create(&pb, NULL, &func, NULL);
pthread_join(pa, NULL);
pthread_join(pb, NULL);
return 0;
}
void * func(void *avg)
{
int i, val;
for(i=0; i
分别按照加-DLOCK和不加编译执行,就能看出锁的重要性了。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/1574/showart_221734.html |
|