Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1907216
  • 博文数量: 383
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 4061
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-24 18:53
文章分类

全部博文(383)

文章存档

2011年(1)

2010年(9)

2009年(276)

2008年(97)

我的朋友
博文列表
标题:
标题 阅读 评论 转发 发布日期
c++ 虚函数的实现机制 1945 1 0 2009-04-28
我到底在追求什么?【转载】 1366 1 0 2009-04-27
中国古代34位美女 1285 0 0 2009-04-24
c语言之宏预处理命令 2538 0 0 2009-04-24
取消word中的自动项目符号和编号 1541 0 1 2009-04-24
职业生涯中12个最致命的想法 827 0 1 2009-04-22
使驱动程序同时支持Linux2.4和2.6内核的方法 2955 0 2 2009-04-19
读高阳《胡雪岩》 4139 0 0 2009-04-19
引起进程调度的原因 4736 0 0 2009-04-18
从文件I/O 看Linux 的虚拟文件系统 1135 0 0 2009-04-18
网卡驱动实例解读分析(经典!!!) 2251 0 3 2009-04-18
深入浅出分析Linux设备驱动程序中断 1252 0 0 2009-04-18
12种容易创业失败的典型人物 799 0 0 2009-04-18
人活着,不是靠同情和怜悯 847 0 0 2009-04-18
extern "C" 1350 0 0 2009-04-16
C语言实现双向循环链表 9280 1 4 2009-04-16
什么是子网掩码 1995 1 1 2009-04-16
一位研究生导师心目中理想的论文 861 0 0 2009-04-16
Linux编程风格 2020 0 0 2009-04-14
一个人的霸气就决定了他的成就! 1095 0 0 2009-04-14
给主人留下些什么吧!~~

chinaunix网友2011-06-10 17:35

博主你好, 我想买个笔记本,平常要用CAD、3DMAX、photoshop,但是我不懂电脑配置,麻烦你给说说怎么样的配置才行呀,或者推荐几款笔记本也行,3000元左右。

回复 |  删除 |  举报

chinaunix网友2011-05-23 16:00

博主现在不在了吗?我的QQ: 344831602 ,有很急的问题想请教, 谢谢了!!!

回复 |  删除 |  举报

chinaunix网友2010-07-04 03:36

cwj670@qq.com 670400080@qq.com 谢谢

回复 |  删除 |  举报

chinaunix网友2010-07-04 03:32

#include #include #define BUFFER_SIZE 16 struct prodcons { int buffer[BUFFER_SIZE]; pthread_mutex_t lock; int readpos,writepos; pthread_cond_t notempty; pthread_cond_t notfull; }; void init (struct prodcons *b) { pthread_mutex_init(&b->lock,NULL); pthread_cond_init(&b->notempty,NULL); pthread_cond_init(&b->notfull,NULL); b->readpos=0; b->writepos=0; } void put(struct prodcons *b, int data) { { pthread_mutex_lock(&b->lock); if((b->writepos+1)%BUFFER_SIZE==b->readpos) { pthread_cond_wait(&b->notfull,&b->lock); } b->buffer[b->writepos]=data; b->writepos++; if(b->writepos>=BUFFER_SIZE) b->writepos=0; pthread_cond_signal(&b->notempty); pthread_mutex_unlock(&b->lock); } int get(struct prodcons *b) { int data; pthread_mutex_lock(&b->lock); if(b->writepos==b->readpos) { pthread_cond_wait(&b->notempty,&b->lock); } data=b->buffer[b->readpos]; b->readpos++; if(b->readpos>=BUFFER_SIZE) b->readpos=0; pthread_cond_signal(&b->notfull); pthread_mutex_unlock(&b->lock); return data; } #define OVER (-1) struct prodcons buffer; void *producer(void *data) { int n; for(n=0;n<10000;n++) { printf(“%d---->\n”,n); put(&buffer,n); } put(&buffer,OVER); return NULL; } void *consumer(void *data) { int d; while(1) { d=get(&buffer); if(d==OVER) break; printf(“---->%d\n”,d); } return NULL; } int main(void) { pthread_t th_a,th_b; void *retval; init(&buffer); pthread_create(&th_a,NULL,producer,0); pthread_create(&th_b,NULL,consumer,0); pthread_join(th_a,&retval); pthread_join(th_b,&retval); return 0; } 高人,帮个忙把这段程序加上注释呗,详细的,多谢了

回复 |  删除 |  举报

yanhongkang9282010-05-23 20:46

东北大学的学生,做了一年的ARM9蓝牙开发,想和你交个朋友,QQ1217866355

回复  |  举报
留言热议
请登录后留言。

登录 注册