3
int threads = 5;

pthread_t * thread = malloc(sizeof(pthread_t)*threads);

            for (i = 0; i < threads; i++){
                int ret = pthread_create(&thread[i], NULL, &foobar_function, NULL);}

我现在无法运行代码。但是我将其视为在线示例的一部分,并且对完全没有方括号感到有些困惑。我对C不太好。

那么这对创建线程数组有用吗?

4

1 回答 1

3

Yes.

thread is pointing at a block of memory allocated by malloc that is large enough to hold threads pthread_t objects.

An array of threads pthread_t objects can be represented in exactly this way.

于 2012-11-18T02:09:28.960 回答