2013-05-17 131 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之前創建了很多線程嗎? 。在理想情況下不應該在空間問題上失敗。

可能您可以啓動線程屬性,並嘗試在創建線程之前設置堆棧大小。所以我們可以輕鬆縮小範圍。

相關問題