- 论坛徽章:
- 0
|
同意benjiam (xxxx) 的意见,没看出来为什么需要那么多线程。我认为实际上如果任务处理时间很短的话甚至单线程也够用了。
如果只有一个线程读,一个线程写,那么不加锁绝对不危险。当然代码需要仔细斟酌,关键是更新指针的时机。
有一定道理,但我认为还是加锁比较简单、安全。因为正如你所说“当然代码需要仔细斟酌”。而且有个前提是对数据结构的修改可以在一个原子操作内完成。
只有线程调用了pthread_exit或者return,那么线程占用的资源就被释放了
pthread_join的作用是挂起当前的线程,等待另外一个线程结束。
这个观点是错误的。除非线程是detach的,否则它的资源需要pthread_join来回收。以下摘自man page
When a joinable thread terminates, its memory resources (thread
descriptor and stack) are not deallocated until another thread performs
pthread_join on it. Therefore, pthread_join must be called once for
each joinable thread created to avoid memory leaks. |
|