作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在堆栈上有一个线程变量数组,主线程稍后会加入该数组。我稍后必须再次运行相同数量的线程,并且想知道是否仍然可以使用相同的线程结构数组来创建新线程,或者线程结构是否不能再次用于创建新线程。
类似这样的事情:
main_method() {
pthread_t threads[10]
for (all threads)
pthread_create(&threads[i], NULL, some_func, &arg[i])
for (each thread in threads[10])
pthread_join(&threads[i]), ...)
// Does this work?
for (each thread in threads[10])
pthread_create(&threads[i], NULL, other_func, &arg[i])
//Or do I have to do this
pthread_t threads2[10]
for (each thread in threads2[10])
pthread_create(&threads2[i], NULL, other_func, &arg[i])
这里提出了类似的问题,但不确定答案是否解决了上述问题。
最佳答案
当一个线程退出时,它就完成了。你不能“重用”它——创建另一个。当然,您可以重用数组 - 但不能重用其中的值。 (即需要再次pthread_create)
您引用的问题是询问/并发/线程的最大数量 - OP 没有加入或没有让他的线程退出。在程序执行的生命周期内可以使用的线程数量没有限制。
关于c - 在C中的thread_join之后重用线程结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30109564/
Prolog 中的线程不共享其堆栈中的数据(在文档中如此说明)。但是,据我所知,这可以通过使用 thread_join 加入线程来解决。如果我到目前为止所说的任何内容都是错误的,请纠正我。但是,如果一
我是一名优秀的程序员,十分优秀!