摘要: 看下简单的例子: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 pthread_mutex_t glock = PTHREAD_MUTEX_INITIALIZER; 8 struct foo 9 { 10 int f_count; 11 pthread_mutex_t f_lock; 12 }; 13 struct foo* AllocFoo() 14 { 15 foo* lpFoo = (foo*)malloc(sizeof(struct foo)); 16 ... 阅读全文
posted @ 2013-09-23 22:10 hailong 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 默认的编译选项是没有pthread的,所以要自己添加:参考:http://hi.baidu.com/u_soa/item/9d6cc40b7e9d76eb3499024d错误:undefined reference to 'pthread_create'解决:Project -> Build options -> Linker settings -> Link libraries 里加上pthread这样就解决啦!非常感谢老游网友! 阅读全文
posted @ 2013-09-23 21:38 hailong 阅读(2756) 评论(0) 推荐(0) 编辑
摘要: 生产者和消费者问题:当协程调用yield时,从一个悬而未决的resume中返回。简单的协程练习:function receive() local status,value = coroutine.resume(producer) return status,valueendfunction send(x) coroutine.yield(x)endproducer = coroutine.create(function() local x = 0 while true do x = x+1 if(x > 10) then ... 阅读全文
posted @ 2013-09-23 10:19 hailong 阅读(169) 评论(0) 推荐(1) 编辑
摘要: 按照书上写的,不知道为什么有问题://已解决,参考最新的blog,哈哈#include #include #include #include struct foo{ int f_count; pthread_mutex_t f_lock;};struct foo* AllocFoo(){ foo* lpFoo = (foo*)malloc(sizeof(struct foo)); if(NULL != lpFoo) { lpFoo->f_count = 1; if(0 != pthread_mutex_init(&lpFoo->f_lo... 阅读全文
posted @ 2013-09-23 07:22 hailong 阅读(316) 评论(0) 推荐(1) 编辑