Subj : Re: CRT _beginthread returns -1, errno=ENOMEM "Not enough space" on 3GB dualcpu To : comp.programming.threads,comp.os.ms-windows.programmer.nt.kernel-mode,microsoft.public.vc.language From : Severian Date : Thu Mar 31 2005 06:29 am On 30 Mar 2005 21:50:17 -0800, lpdcunha@engmail.uwaterloo.ca (Larry D'Cunha) wrote: >I need some help debugging a program that is hanging because of a >thread problem with _beginthread() multithreaded C-runtime call. I'm >using VS6 debugger to step into the code. > >System: Xeon 3.2GHz, dual cpu, 3.2GB RAM > >Problem: >Two threads are being created. First one created ok. Second one fails. >_beginthread() returns (-1L). I have this: > > thr = _beginthread( (void (*)(void *) )f, stk_size, (void *)arg ); > >Error code I get is: > 1) errno = 12, ENOMEM "Not enough space" > 2) GetLastError() returns 8, ERROR_NOT_ENOUGH_MEMORY > "Not enough storage is available to process this command." > > stk_size passed in 32768 for both threads. MSDN mentions that any thread using the C runtime requires at least a 64KB stack. I think this is a more likely problem in your case than running out of virtual address space, which you can check using Process Explorer from http://www.sysinternals.com, or the memory tools available from http://www.softwareverify.com. >p.s. Aside: I had some CRT-debug problems. I linked msvcrtd.dll >debug-multithreaded CRT into the app. But I could not successfully >step into the code for _beginthread() in thread.c CRT-source file. The >symbols were not found (even though I have msvcrtd.pdb in the path) >These files are all in my VC98 subdirectories. Oh well. Look up the MS symbol server in MSDN. It will keep your symbols up-to-date for all your system DLLs. You set your symbol path to a special string which downloads symbols for system DLLs automatically as needed, and updates them after service packs, updates, patches, etc. -- Sev .