pthread_create没有足够的空间
我在Windows上使用Pthreads和MinGW。 对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");
错误消息最可能是错误的,因为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"); }
这将为您提供正确的错误消息。
这很奇怪,虽然我不确定MinGW,是的,它应该指的是堆栈大小。 这是什么类型的应用程序? 你在这个parserThread之前创建了很multithreading吗? 。 理想情况下不应该在太空问题上失败。
可能你可以启动线程属性,并尝试在创建线程之前设置stacksize。 所以我们可以轻松缩小范围。