Skip to main content

Thread: Are thread stacks virtual?


i new threads , have been googling bit find out sizes of thread stacks. wrote pthread_attr_setstacksize allocates space in virtual memory no physical behind it. so?

want put application on server using sockets multi threading using 1 thread each connection. there 1 procedure 'listener' each connection run by/in thread. each connection needs workspace , code snippet below gets workspace simple array declaration on entry procedure. workspace stays long procedure active (carryon true) , automatically returned on exit.

code:
bool carryon = true ;  void listener ( )     {     char workspace [ 500000 ] ;   // allocated on thread stack       while ( carryon )        {        waitforclientmessage() ;        actonmessage ( workspace ) ;   // pass workspace handler         }     }
there delays when actonmessage running if kernel has map in missing physical memory. how significant these be? for first client message, i.e. kernel leave physical memory alone once allocated thread stack?

allocating memory char * space = new char[ 500000 ] behave differently?

way best or fastest?

i think posix threads come 8mb of stack size. if you're running out of stack space, algorith should reworked use heap allocation.

stack allocation faster limited. programs use virtual addressing. in way see "whole memory".


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Are thread stacks virtual?


Ubuntu

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support