How to spawn from big-stack program
Dave Korn
dave.korn.cygwin@googlemail.com
Sun Jul 5 12:26:00 GMT 2009
Klaus Grue wrote:
> Hi,
>
> Can anyone tell me how to invoke a program from a big-stack program
> (i.e. a program which has a big stack). Here is a small big-stack
> program which reproduces the problem:
The problem is not spawning the new executable. The problem is that you've
set the default thread stack size to 500 meg. Your main thread starts up,
that's half a gig gone. The cygwin internal signal handling thread starts up,
another half a gig gone. You've only got 2 gig of user-addressable memory
space, and there's a lot of DLLs at the top of it and your exe down at the low
end. When you try and spawn the new process, cygwin needs to fire up another
internal thread to handle synchronisation with the newly-started process.
This takes place at /gnu/winsup/src/winsup/cygwin/pinfo.cc:955:
953 waiter_ready = false;
954 /* Fire up a new thread to track the subprocess */
955 cygthread *h = new cygthread (proc_waiter, 0, this, "proc_waiter");
... where it constructs a new cygthread object; the cygthread constructor at
/gnu/winsup/src/winsup/cygwin/cygthread.cc:189 calls CreateThread:
188 cygthread::cygthread (LPTHREAD_START_ROUTINE start, size_t n, void *param,
189 const char *name, HANDLE notify)
190 : __name (name), func (start), arglen (n), arg (param),
notify_detached (notify)
191 {
192 thread_printf ("name %s, id %p", name, id);
193 HANDLE htobe;
194 if (h)
195 {
[ .. snipped ... not relevant here ... ]
203 }
204 else
205 {
206 stack_ptr = NULL;
207 htobe = CreateThread (&sec_none_nih, 0, is_freerange ?
simplestub: stub,
208 this, 0, &id);
209 if (!htobe)
210 api_fatal ("CreateThread failed for %s - %p<%p>, %E", name, h,
id);
But there simply isn't quite enough room (the memory map is a bit fragged by
the layout described above) for another 500 meg stack, so the thread creation
fails and everyone goes home and sulks.
It's possible we could tweak cygwin to not use the default thread stack size
for these internal threads.
If you want a workaround, you could try leaving the default thread size in
your executable, and in your main() function use pthread_create to spawn a
worker thread to do the real processing, having set a large stacksize for it
using the related pthread_attr_setstacksize function.
> On the Vista machine I did
> cygcheck -s -v -r > cygcheck.out
> I stopped it after it had generated 10MB of output. I have merely
> attached the first 39329 bytes of cygcheck.out. It looks like cygcheck
> loops indefinitely.
Hmm, are you running with a slightly outdated version? I thought we had
fixed that one. (MS decided to change the registry from a simple tree to a
directed graph with cycles in order to support WoW64. Not a clever move IMO).
cheers,
DaveK
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list