public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: stack size issues, multi-threading
@ 1997-08-05 22:24 Colin Peters
  0 siblings, 0 replies; 4+ messages in thread
From: Colin Peters @ 1997-08-05 22:24 UTC (permalink / raw)
  To: 'Larry Meadows'; +Cc: 'GNU-Win32'

Larry Meadows[SMTP:lfm@pgroup.com] wrote:
>1. How do I increase the stack size for an application? Is this done
>at link time, or can it be done at run time.
>
>2. How are stacks allocated for multi-threaded applications.

As Mikey said:

gcc -Wl,--heap,1024,--stack,4096 -o blah blah.c

for setting the heap and or stack of an executable.

Now for question 2:

You can set the stack size of threads as an argument to CreateThread
under Win32:

HANDLE CreateThread(
   LPSECURITY_ATTRIBUTES lpsa,
   DWORD cbStack,
   LPTHREAD_START_ROUTINE lpStartAddr,
   LPVOID lpvThreadParm,
   DWORD fdwCreate,
   LPDWORD lpIDThread);
  

Set cbStack to the number of bytes you wish to commit as an initial
stack size. You can also pass zero, in which case the same value as
was used for the primary thread (this is 0x1000, or 4 KB, and is not
affected by the --stack option) will be used.

It is my understanding that this size is not an upper limit on the
stack size of the thread, but only an initial size (and size to grow
by). This is based on the following passage from "Advanced Windows":

---quote---
The cbStack parameter specifies how much address space the thread is allowed to use for its own stack. Every thread owns its very own stack. When CreateProcess starts an application, it calls CreateThread to initialize the process's primary thread. For the cbStack parameter, CreateProcess uses the value stored inside the executable file. You can control this value using the linker's /STACK switch:
  
/STACK:[reserve] [,commit]
  
The reserve argument sets the amount of memory the system should reserve in the address space for the thread's stack. The default is 1 MB. The commit argument specifies the amount of reserved address space that should initially be committed to the stack. The default is 1 page. (See Chapter 6 for a discussion of reserving and committing memory.) As the code in your thread executes, it is quite possible that you'll require more than 1 page of memory. When your thread overflows its stack, an exception is generated. (See Chapter 14 for detailed information about handling exceptions.) The system catches the exception and commits another page (or whatever you specified for the commit argument) to the reserved space, which allows your thread's stacks to grow dynamically as needed.

When calling CreateThread you can pass 0 to the cbStack parameter. In this case, CreateThread creates a stack for the new thread using the commit argument embedded in the EXE file by the linker. The amount of reserved space is always 1 MB. The system sets a limit of 1 MB to stop functions that recurse endlessly.

---endquote---

The --stack option appears to change the "reserve" value (or upper
limit) on stack size. However, there seems to be no way to change
the upper limit on a thread's stack space (still, "1 MB of stack!?
What are you thinking!?").

It does seem that, other than possible efficiency issues, there's not much
point in setting the stack size, since it will grow dynamically anyway
(that is, if someone hasn't installed a buggy exception handler and messed
things up).

Hope this helps,
Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stack size issues, multi-threading
       [not found] <199708051550.IAA01312@pacific.pgroup.com>
@ 1997-08-05 13:15 ` Mikey
  0 siblings, 0 replies; 4+ messages in thread
From: Mikey @ 1997-08-05 13:15 UTC (permalink / raw)
  To: Larry Meadows, gnu-win32

.../cdk/ld/emultempl/pe.em

The obvious place ;^).

Pointed out by Sergey about 2 months ago.

On Tue, 5 Aug 1997 08:50:00 -0700 (PDT), you wrote:

>> gcc -Wl,--heap,1024,--stack,4096 -o blah blah.c
>
>Thanks. Boy, I don't even see that in the source code, much less
>the documentation.
>
>lfm
>

(jeffdbREMOVETHIS@netzone.com)
delete REMOVETHIS from the above to reply
         Mikey
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: stack size issues, multi-threading
  1997-08-04 12:01 Larry Meadows
@ 1997-08-05  0:03 ` Mikey
  0 siblings, 0 replies; 4+ messages in thread
From: Mikey @ 1997-08-05  0:03 UTC (permalink / raw)
  To: Larry Meadows, gnu-win32

gcc -Wl,--heap,1024,--stack,4096 -o blah blah.c

On Mon, 4 Aug 1997 12:00:55 -0700 (PDT), you wrote:

>I apologize if this is an FAQ, I looked...
>
>1. How do I increase the stack size for an application? Is this done
>at link time, or can it be done at run time.
>
>2. How are stacks allocated for multi-threaded applications.
>
>tia
>
>lfm
>-
>For help on using this list (especially unsubscribing), send a message to
>"gnu-win32-request@cygnus.com" with one line of text: "help".
>

(jeffdbREMOVETHIS@netzone.com)
delete REMOVETHIS from the above to reply
         Mikey
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* stack size issues, multi-threading
@ 1997-08-04 12:01 Larry Meadows
  1997-08-05  0:03 ` Mikey
  0 siblings, 1 reply; 4+ messages in thread
From: Larry Meadows @ 1997-08-04 12:01 UTC (permalink / raw)
  To: gnu-win32

I apologize if this is an FAQ, I looked...

1. How do I increase the stack size for an application? Is this done
at link time, or can it be done at run time.

2. How are stacks allocated for multi-threaded applications.

tia

lfm
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-08-05 22:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-05 22:24 stack size issues, multi-threading Colin Peters
     [not found] <199708051550.IAA01312@pacific.pgroup.com>
1997-08-05 13:15 ` Mikey
  -- strict thread matches above, loose matches on Subject: below --
1997-08-04 12:01 Larry Meadows
1997-08-05  0:03 ` Mikey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).