CreateFiber() : number of fibers limited

Danny Smith danny_r_smith_2001@yahoo.co.nz
Mon Jun 4 01:44:00 GMT 2001


--- Danny Smith <danny_r_smith_2001@yahoo.co.nz> wrote: > 
> --- Dan Plimak <danp@systematik.co.nz> wrote: > On Sun, Jun 03, 2001 at
> 12:16:07PM +0200, Holger Vogt wrote:
> > > Hi,
> > > 
> > > independently of the requested stack size (first parameter in
> > > CreateFiber()), CYGWIN will give only 53 fibers. Only when I increase
> > > the stack size above 9.5 MByte, I will get a further reduction in the
> > > number of fibers created.
> > 
> > I was intrigued by this difference between gcc and Borland C++Builder and
> MS
> > Visual C++, so I tried the following code under all three compilers on
> > Win2K:
> > 
> > ---
> > 
> > #define _WIN32_WINNT 0x0500 /* Coax winbase.h into including
> >                                ConvertThreadToFiber() */
> > #include <windows.h>
> > #include <stdio.h>
> > 
> > #define MEG       (1024 * 1024)
> > #define STACKSIZE (MEG * 2)
> > 
> > int main()
> > {
> >         int param = 0, i = 0;
> >         LPFIBER_START_ROUTINE saddr = NULL;
> >         LPVOID foo;
> > 
> >         ConvertThreadToFiber(&param);
> > 
> >         while(++i) {
> > 
> >                 foo = CreateFiber(STACKSIZE, saddr, &param);
> > 
> >                 if(foo != NULL)
> >                         printf("Created fiber 0x%08x.\n", foo);
> >                 else {
> >                         printf("Failed to create fiber at iteration %d;\n"
> >                                 "stack space allocated: %dMB\n",
> >                                 i, (STACKSIZE * i) / MEG);
> >                         break;
> >                 }
> >         }
> > 
> >         return 0;
> > }
> > 
> > ---
> > 
> > The results are definitely interesting. The runtime code generated by VC++
> > (6.0) and BCB (bcc32.exe v5.5) will allow stack allocation by fibers until
> > total stack space allocated hits the free memory limit on the system.
> > 
> > Whereas with gcc, no matter how small you make your stack, the maximum
> > number of fibers will be 52. (If it was 42, I'd suspect somebody was taking
> > the Hitchhiker's Guide to the Galaxy a wee bit too seriously.)
> > 
> > All in all, I don't think this is a bug in the library. It definitely looks
> > like a hard limit on the number of stacks/fibers you can allocate --
> > something of the sort Danny Smith proposed, but "harder". Without looking
> at
> > the source, I doubt anybody would be able to pin it down (unless they
> happen
> > to be the gcc maintainer).
> > 
> > You might want to ask on the gcc mailing list(s).
> > 
> > Cheers,
> > 
> >   -- danp
> 
> Try changing the stacksize when build the app,
> eg:

I've gotten someone to build your test with MSVC (linking against msvcrt.dll,
no optimisation)
The output on my machine  was:
...
Failed to create fiber at iteration 100;
stack space allocated: 200MB


With mingw-built exe, setting stack reserve to msvc default
gcc -Wl,--stack,0x100000 fiber.c

I get this output on same machine, in same DOS prompt window:
...
Failed to create fiber at iteration 100;
stack space allocated: 200MB

With cygwin-built exe, setting stack reserve to msvc default
gcc -Wl,--stack,0x100000 fiber.c

I get this output on same machine, in same DOS prompt window:
...
Failed to create fiber at iteration 100;
stack space allocated: 200MB


If I run each of the above from bash shell I get
Failed to create fiber at iteration 99;
stack space allocated: 198MB


Close enough for me.
Danny




_____________________________________________________________________________
http://messenger.yahoo.com.au - Yahoo! Messenger
- Voice chat, mail alerts, stock quotes and favourite news and lots more!

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list