This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Unable to allocate heap


CreateFileMapping() is fine. I think the problem is a race condition in
shared_info::heap_chunk_size(). The heap_chunk member is in
process-to-process shared memory, and in my case both find and xargs enter
the function at approximately the same time and attempt to initialise the
same instance of heap_chunk.

One possible outcome is that one of the processes is returning heap_chunk at
the point where the other process has just set it to the (in-megabytes)
value obtained from the registry (hence "heap_chunk_size 384"). Another
possible outcome is that one of the processes executes the <<= 20 just after
the other process has already set the (in bytes) heap_chunk value. This
could give rise to "heap_chunk_size 0" which other correspondents were
seeing before the stop-gap was added in a recent version of shared.cc.

One solution would be to use a local variable instead of heap_chunk itself,
and then assign to heap_chunk at the last gasp. I suppose this would only
work if the assignment to heap_chunk could be guaranteed to be atomic.
Perhaps a mutex would be safer?

-----Original Message-----
From: Jon Jansen [mailto:JonJ@climax.co.uk]
Sent: 01 September 2003 17:17
To: cygwin@cygwin.com
Subject: Unable to allocate heap


I get the following error running CygWin find and xargs from within a TCL
script:

    Error executing 'C:/cygwin/bin/find TempDir/QACData -name *.lock -type f
-print0 | xargs -0r rm -r'...
    c:\cygwin\bin\xargs.exe: *** unable to allocate heap, heap_chunk_size
384, Win32 error 0

The error is intermittent and I haven't been able to reproduce it outside
the TCL script (whether from bash, cmd, tclsh, whatever).

There's similar prior art in the archives, but this one has the crucial
difference that the reported heap_chunk_size is small but non-zero.

I've had a look through the relevant source (shared.cc, heap.cc), and my
initial thought was that shared_info::heap_chunk_size() was returning a
rogue size for some reason. It seems that the memory-zeroing behaviour of
Win32 CreateFileMapping() is used to initialise shared_info::heap_chunk to
zero. Is CreateFileMapping() completely trustworthy in this respect?


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]