Re: problem of stack size in st_thread_create()

Alfred Zhong <[email protected]> Wed, 10 Aug 2011 13:32:59 -0400
Newsgroups gmane.comp.lib.state-threads.user,gmane.comp.lib.state-threads.devel
Message-ID <CAFU3TiKaAXZ5_1_YKJY7Q9tXaSJoXTQq_-BBQ4k63Kj8roeWXg@mail.gmail.com>
--===============8978906115680044493==
Content-Type: multipart/alternative; boundary=90e6ba48856d4cef1c04aa2a129a

--90e6ba48856d4cef1c04aa2a129a
Content-Type: text/plain; charset=ISO-8859-1

Oh my god!

+ _ST_PAGE_SIZE - 1

if stk_size is just x times of the _ST_PAGE_SIZE, the integer division will
return exactly x b/c of the -1.

if stk_size is smaller than x times of _ST_PAGE_SIZE, the integer division
will return exactly x, and ignore the remaining >x but <x+1

That is smart!
If the purpose is in the comment or docs will be better to understand

Thanks a lot, John!

Alfred

On Wed, Aug 10, 2011 at 1:11 PM, John Newton <[email protected]> wrote:

> The line you are asking about is a "round up" to the next page size
> calculation.
>
> For example, if getpagesize() returns 4096, and the "stk_size" parameter is
> 10,000 it would round up to the next even page size. (the division is doing
> integer math)
>
> Hope this helps!
>
> On Wed, Aug 10, 2011 at 9:06 AM, Alfred Zhong <[email protected]>wrote:
>
>> Hi,
>> I am new to state thread library and am reading the source code of ST to
>> study implementation of threading.
>>
>> in the st_thread_create() function
>>
>> there is this code piece
>>
>> if (stk_size == 0)
>>     stk_size = ST_DEFAULT_STACK_SIZE;  // I know this is to set the stack
>> size to a default size, if the input size is 0
>>   stk_size = ((stk_size + _ST_PAGE_SIZE - 1) / _ST_PAGE_SIZE) *
>> _ST_PAGE_SIZE; //what does this mean?
>>
>> Look like it equals (stk_size + ST_PAGE_SIZE -1) unless the previous
>> division gives 0.
>>
>> I am totally confused and can't find the answer in the code or the docs,
>> please help!
>>
>> Thanks a lot!
>> Alfred
>>
>>
>> ------------------------------------------------------------------------------
>> uberSVN's rich system and user administration capabilities and model
>> configuration take the hassle out of deploying and managing Subversion and
>> the tools developers use with it. Learn more about uberSVN and get a free
>> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>>
>> _______________________________________________
>> State-threads-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/state-threads-users
>>
>>
>

--90e6ba48856d4cef1c04aa2a129a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Oh my god!<div><br></div><div>+=A0_ST_PAGE_SIZE - 1</div><div><br></div><di=
v>if stk_size is just x times of the _ST_PAGE_SIZE, the integer=A0division =
will return exactly x b/c of the -1.</div><div><br></div><div>if stk_size i=
s smaller than x times of _ST_PAGE_SIZE, the integer division will return e=
xactly x, and ignore the remaining &gt;x but &lt;x+1=A0</div>
<div><br></div><div>That is smart!=A0</div><div>If the purpose is in the co=
mment or docs will be better to understand</div><div><br></div><div>Thanks =
a lot, John!</div><div><br></div><div>Alfred</div><div><br><div class=3D"gm=
ail_quote">
On Wed, Aug 10, 2011 at 1:11 PM, John Newton <span dir=3D"ltr">&lt;<a href=
=3D"mailto:[email protected]">[email protected]</a>&gt;</span> wrote:<br><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex;">
The line you are asking about is a &quot;round up&quot; to the next page si=
ze calculation.<div><br></div><div>For example, if getpagesize() returns 40=
96, and the &quot;stk_size&quot; parameter is 10,000 it would round up to t=
he next even page size. (the division is doing integer math)</div>

<div><br></div><div>Hope this helps!</div><div><br><div class=3D"gmail_quot=
e"><div><div></div><div class=3D"h5">On Wed, Aug 10, 2011 at 9:06 AM, Alfre=
d Zhong <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" targe=
t=3D"_blank">[email protected]</a>&gt;</span> wrote:<br>

</div></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class=3D"h5=
"><span style=3D"font-family:arial, sans-serif;font-size:13px;background-co=
lor:rgb(255, 255, 255)">Hi,<div>
I am new to state thread library and am reading the source code of ST to st=
udy implementation of threading.=A0</div>

<div><br></div><div>in the st_thread_create() function</div><div><br></div>=
<div>there is this code piece</div><div><br></div><div><div>if (stk_size =
=3D=3D 0)</div><div>=A0 =A0 stk_size =3D ST_DEFAULT_STACK_SIZE; =A0// I kno=
w this is to set the stack size to a default size, if the input size is 0</=
div>


<div>=A0 stk_size =3D ((stk_size + _ST_PAGE_SIZE - 1) / _ST_PAGE_SIZE) * _S=
T_PAGE_SIZE; //what does this mean?</div></div><div><br></div><div>Look lik=
e it equals (stk_size + ST_PAGE_SIZE -1) unless the previous division gives=
 0.</div>


<div><br></div><div>I am totally confused and can&#39;t find the answer in =
the code or the docs, please help!</div><div><br></div><div>Thanks a lot!</=
div><div>Alfred</div></span>
<br></div></div>-----------------------------------------------------------=
-------------------<br>
uberSVN&#39;s rich system and user administration capabilities and model<br=
>
configuration take the hassle out of deploying and managing Subversion and<=
br>
the tools developers use with it. Learn more about uberSVN and get a free<b=
r>
download at: =A0<a href=3D"http://p.sf.net/sfu/wandisco-dev2dev" target=3D"=
_blank">http://p.sf.net/sfu/wandisco-dev2dev</a><br>
<br>_______________________________________________<br>
State-threads-users mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_bla=
nk">[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/state-threads-users=
" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/state-thre=
ads-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>

--90e6ba48856d4cef1c04aa2a129a--


--===============8978906115680044493==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev

--===============8978906115680044493==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
State-threads-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/state-threads-users

--===============8978906115680044493==--