2013-05-17 128 views
0

我在Windows上使用带有MinGW的Pthreads。对pthread_create的调用返回一个错误,该错误转换为“空间不足”。它指的是什么样的空间?线程堆栈空间?pthread_create没有足够的空间

int scannerThreadReturnValue = pthread_create(&parserThreadHandle, &attr, parserThread, (void *)filename); 
    if(scannerThreadReturnValue != 0) { 
     printf("Unable to create thread %s\n", strerror(errno)); 
    } 
    else printf("Parser thread creation successfull\n"); 
+0

检查'pthread_create()'参数的第四个参数段落到'parserThread()'必须作为指针传递给struct,你使用的是attr?否则将其设置为NULL –

回答

1

由于pthread_*功能系列没有设置errno,因此错误消息最可取的是错误的。错误代码由函数返回。

所以国防部您这样的代码:

int scannerThreadReturnValue = pthread_create(&parserThreadHandle, &attr, parserThread, (void*)filename); 
if (scannerThreadReturnValue != 0) 
{ 
    printf("Unable to create thread: %s\n", strerror(scannerThreadReturnValue)); 
} 
else 
{ 
    printf("Parser thread creation successful.\n"); 
} 

这会给你正确的错误消息。

0

这很奇怪,虽然我不确定MinGW,但是它应该指的是堆栈大小。这是什么类型的应用程序?你在这个parserThread之前创建了很多线程吗? 。在理想情况下不应该在空间问题上失败。

可能您可以启动线程属性,并尝试在创建线程之前设置堆栈大小。所以我们可以轻松缩小范围。

相关问题