pthread 学艺不精,求修炼用的文档。

88 views
Skip to first unread message

none_nobody

unread,
Apr 17, 2014, 3:25:36 AM4/17/14
to sh...@googlegroups.com

我就会两个调用接口  pthread_create( pids, NULL , func ,args ) 和 pthread_mutex_init( &, NULL ) 好像不够用。

诸神指条明路。

孑影

unread,
Apr 17, 2014, 3:59:48 AM4/17/14
to sh...@googlegroups.com
搭车 ,求 libev libuv 相关修炼 文档



#风起看云涌,叶落品人生#
> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout

DaboD

unread,
Apr 17, 2014, 4:04:25 AM4/17/14
to sh...@googlegroups.com
libuv 用過, 沒文檔能分享, 但可討論.
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+unsubscribe@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout

孑影

unread,
Apr 17, 2014, 8:24:23 AM4/17/14
to sh...@googlegroups.com
喵,,,一般 采用 libuv 这种 类型的网络库,,, 有什么通用的方法解决 粘包 分包 半包的 问题
#风起看云涌,叶落品人生#
>> > 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
>> > 要查看更多选项,请访问https://groups.google.com/d/optout
>
> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout

none_nobody

unread,
Apr 17, 2014, 9:35:47 AM4/17/14
to sh...@googlegroups.com
pthread 又复习了一遍,大概意思反覆地调用pthread_create是不行的,总有地方吃不消。

1.是要么还是要有个线程池
2.要么彻底要将线程管起来,那些简单的例子中的NULL参数都是坑,mutexattr 也是这样。
要么deatach,  要么pthread_exit , pthread_join ,多线程环境下这些调用都是坑。

话说一个带优先级的线程池都可以卖钱。

Chaos Eternal

unread,
Apr 17, 2014, 11:38:39 AM4/17/14
to sh...@googlegroups.com
果断corouting啊

none_nobody

unread,
Apr 17, 2014, 11:44:06 AM4/17/14
to sh...@googlegroups.com
云风的 coroutine 没有用pthread

在提到 mutex attribute defines four types时, 好像没有特意说明linux是否完整都实现了。


On Thursday, April 17, 2014 11:38:39 PM UTC+8, Soahc Lanrete wrote:
果断corouting啊


Yang Fan

unread,
Apr 17, 2014, 10:23:47 PM4/17/14
to sh...@googlegroups.com
确实是各种坑啊。前段时间我负责的一个功能总是跑一段时间就再也创建不了线程了,而创建线程的代码是从同一产品其他地方copy过来的,后来网上一查就说“要么deatach,  要么pthread_exit , pthread_join”,只有我那块是会反复创建退出线程的,所以才暴这问题,其他地方的线程都只创建一次,所以即使代码没写对也不影响实际运行。。。


2014-04-17 21:35 GMT+08:00 none_nobody <lyx...@gmail.com>:

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout



--
Regards,
Fan Yang

none_nobody

unread,
Apr 17, 2014, 10:43:01 PM4/17/14
to sh...@googlegroups.com
又被我抓住了错误的信息,先贴再找办法。

tpp.c:63: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.


On Friday, April 18, 2014 10:23:47 AM UTC+8, Fan Yang wrote:
确实是各种坑啊。前段时间我负责的一个功能总是跑一段时间就再也创建不了线程了,而创建线程的代码是从同一产品其他地方copy过来的,后来网上一查就说“要么deatach,  要么pthread_exit , pthread_join”,只有我那块是会反复创建退出线程的,所以才暴这问题,其他地方的线程都只创建一次,所以即使代码没写对也不影响实际运行。。。


pthread_create 不是可以随便就反复调用的。而且还不能多。云风的coroutine不用pthread 用swapcontext还是n有道理的

liyaoshi

unread,
Apr 17, 2014, 10:47:19 PM4/17/14
to sh...@googlegroups.com
照你这么一说,我还真想不起来哪家产品是没事自己创建了以后自己退出,然后再创建

这是没事找抽型么?

我们好像一直多是只管创建,不管他怎么退出,到时候总归会断电的。。。

只管杀来不管埋唉


--

none_nobody

unread,
Apr 17, 2014, 10:49:17 PM4/17/14
to sh...@googlegroups.com
其实吧,这种多线程的坑和五王之战差不多,winterfell的混战中根本就不知道卡丽熙的龙蛋孵化了没有。

代码有错改起来很简单,只是不知道在哪里做错了。所以最好有个类似 valgrind 的工具专门进行线程检查,

还好,我人生只是单线程的,没法pthread_create一个出来专门写这个工具。

On Friday, April 18, 2014 10:43:01 AM UTC+8, none_nobody wrote:
又被我抓住了错误的信息,先贴再找办法。

Yang Fan

unread,
Apr 17, 2014, 11:54:49 PM4/17/14
to sh...@googlegroups.com
就算产品实际情况几天只走一次那段逻辑,走完就关机了,压力测试一上就暴露了。
--
Regards,
Fan Yang

none_nobody

unread,
Apr 18, 2014, 12:24:26 AM4/18/14
to sh...@googlegroups.com
多线程奏是这样,每次都出错,每次提示的错误都还不一样。



On Friday, April 18, 2014 11:54:49 AM UTC+8, Fan Yang wrote:
就算产品实际情况几天只走一次那段逻辑,走完就关机了,压力测试一上就暴露了。


none_nobody

unread,
Apr 18, 2014, 1:03:31 AM4/18/14
to sh...@googlegroups.com
就算设置了这种保护也没有用,还是一样的corrupt.

    pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
    pthread_mutexattr_setkind_np (&mutexattr, PTHREAD_MUTEX_ERRORCHECK_NP);


On Friday, April 18, 2014 12:24:26 PM UTC+8, none_nobody wrote:
多线程奏是这样,每次都出错,每次提示的错误都还不一样。

none_nobody

unread,
Apr 18, 2014, 1:05:02 AM4/18/14
to sh...@googlegroups.com
我一定还是遗漏了什么

On Friday, April 18, 2014 1:03:31 PM UTC+8, none_nobody wrote:
就算设置了这种保护也没有用,还是一样的corrupt.

david pu

unread,
Apr 18, 2014, 5:04:08 AM4/18/14
to sh...@googlegroups.com
来个跑题的,调试这种玩意的高级工具rr:http://rr-project.org

不过为什么会不停create线程呢?
> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout



--
() ASCII Ribbon Campaign
/\ Keep it simple!

none_nobody

unread,
Apr 18, 2014, 5:15:34 AM4/18/14
to sh...@googlegroups.com
见到过rr,还不会用。

说起不停创建线程这事,不是因为先用了一个定时器,定时到了之后呢,有三四种不同的任务,

有的任务去同步其他机器上的分散的数据,同步过程的也还需要并发,否则 |查|返回|查|返回|查|返回| 这样太慢了。

有些要对这些同步来的数据做规整,

有些要把这些数据再打乱组合,然后再发射出去。


这么样子的乱,直接一个任务吊起一个线程比较直观。

none_nobody

unread,
Apr 18, 2014, 5:36:46 AM4/18/14
to sh...@googlegroups.com
还有一种情况,就是起了一个线程在接收消息,而收到消息后处理的过程可能会长,影响原来的线程接收消息的工作。

各么收到消息,打一下包,传给一个线程去单独处理。



On Friday, April 18, 2014 5:15:34 PM UTC+8, none_nobody wrote:

说起不停创建线程这事,不是因为先用了一个定时器,定时到了之后呢,有三四种不同的任务,


fei dong

unread,
Apr 18, 2014, 8:51:20 AM4/18/14
to sh...@googlegroups.com
多线程管理和内存管理放一起才是大垦。线程创建太多会把系统资源消耗光的。想办法搞个线程池吧。
--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout


--
中国好人

none_nobody

unread,
Apr 18, 2014, 9:48:43 AM4/18/14
to sh...@googlegroups.com
有个小线程池100行代码,觉得不给力,有点淡淡的忧桑,就想跳过跳过,就折了。

内存池,一直想很想,可是木有啊。

On Friday, April 18, 2014 8:51:20 PM UTC+8, fei dong wrote:
多线程管理和内存管理放一起才是大垦。线程创建太多会把系统资源消耗光的。想办法搞个线程池吧。


DaboD

unread,
Apr 18, 2014, 10:23:07 AM4/18/14
to sh...@googlegroups.com
如果能的話, 限制編程模型, 減少跨 thread 直接共享資源的存取.

建立各 thread 自己的 task queue, 要其他 thread 做什麼事就往那個 thread 的 queue 裡丟 task, 該 task 只會存取對該 thread 來說是 thread safe 的 resource. 這樣, 好處是同步只發生在 queue 上, 而不是 lock/unlock 散落各處, 好調適. 再來是 task 動作時只存取自己 thread 的資源, 可以最高效執行, 且 code 相對清楚易懂.

Chaos Eternal

unread,
Apr 18, 2014, 8:56:58 PM4/18/14
to sh...@googlegroups.com
果断用thread-mailbox啊。

zeromq就是这么干的

none_nobody

unread,
Apr 18, 2014, 9:26:47 PM4/18/14
to sh...@googlegroups.com
这个主意不错。

task queue这个主意好,我研究一下小chaos说的zmq代码thread-mailbox。

none_nobody

unread,
Apr 18, 2014, 11:05:23 PM4/18/14
to sh...@googlegroups.com
感谢各位高人指点,又增强了 thread 的知识。

Chaos Eternal

unread,
Apr 20, 2014, 8:45:43 AM4/20/14
to sh...@googlegroups.com
忘记说了,这对GC也是一大挑战。ZMQ的做法是不要zerocopy, 牺牲一定的性能。

none_nobody

unread,
Apr 22, 2014, 10:30:00 PM4/22/14
to sh...@googlegroups.com
gcc 4.9 支持 Version 4.0 of the OpenMP specification is now supported for the C and C++ compilers. The new -fopenmp-simd option can be used to enable OpenMP's SIMD directives, while ignoring other OpenMP directives. The new -fsimd-cost-model= option permits to tune the vectorization cost model for loops annotated with OpenMP and Cilk Plus simd directives; -Wopenmp-simd warns when the current costmodel overrides simd directives set by the user.


又白忙活了。直接升级gcc 就得了。

Reply all
Reply to author
Forward
0 new messages