Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ace-users] Thread stack size does not take effect

127 views
Skip to first unread message

Venkatraju

unread,
Jan 9, 2007, 10:28:29 AM1/9/07
to ace-...@cs.wustl.edu
Hi,

I am not able to set stack size for ACE_Threads. More details in the PRF
below. Please let me know if you need any additional information.

Thanks in advance.
Venkat


ACE VERSION: 5.5.4

HOST MACHINE and OPERATING SYSTEM: i686, Linux, Fedora Core 5

TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
COMPILER NAME AND VERSION (AND PATCHLEVEL): gcc version 4.1.1
20060525 (Red Hat 4.1.1-1)

THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform-
specific file, simply state which one]:

THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE [if you
use a link to a platform-specific file, simply state which one
(unless this isn't used in this case, e.g., with Microsoft Visual
C++)]:

CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
(used by MPC when you generate your own makefiles):

AREA/CLASS/EXAMPLE AFFECTED:
Setting thread stack size when spawning ACE_Thread does not take effect.

DOES THE PROBLEM AFFECT:
EXECUTION of the application is affected.

SYNOPSIS:
Passing the thread stack size in ACE_Thread::spawn does not take effect.
A similar program that uses pthread_attr_setstacksize works fine.

DESCRIPTION:
Sample program below:
=======================================================
#include <iostream>

#include "ace/Thread.h"
#include "ace/Synch.h"
static int number=0;
static int seed = 0;

static void* worker(void *arg)
{
ACE_UNUSED_ARG(arg);
ACE_OS::sleep(50000);
return 0;
}

int main(int argc, char *argv[])
{
if(argc<2)
{
ACE_DEBUG((LM_DEBUG,"Usage: %s <number of threads>\n", argv[0]));
ACE_OS::exit(1);
}

const int NUM_THREADS=ACE_OS::atoi(argv[1]);
ACE_thread_t *threadID = new ACE_thread_t[NUM_THREADS];
ACE_hthread_t *threadHandles = new ACE_hthread_t[NUM_THREADS];

for (int i=0; i < NUM_THREADS; i++) {
ACE_Thread::spawn(
(ACE_THR_FUNC)worker, //entry point for new thread
0, //args to worker
THR_JOINABLE | THR_NEW_LWP, //flags
&threadID[i], // t_id
&threadHandles[i], // t_handle
ACE_DEFAULT_THREAD_PRIORITY, // priority
0, // stack
2 * 1024 * 1024 // stack size
);
}

for(int i=0; i<NUM_THREADS; i++) {
ACE_Thread::join(threadHandles[i]);
//Wait for all the threads to exit before you let the main fall through
//and have the process exit.
}

return 0;
}
=======================================================

The above test program is built and run. I monitor the stack size using:
"ps -eo pid,size,cmd | grep -i thread"
The stack size printed when run with 4 as the first argument is 41260K.
When the argument is 8, it is 82240K etc.

Wrote a similar program the uses pthread_attr_setstacksize directly.
With 4 threads, that program uses 8460K. With 8 threads, it shows
16668K as expected.

The ACE_Thread version does not seem to take stack sizes below 10MB?

Not sure if this is helpful:
"nm libACE.so.5.5.0 | grep stacksize" shows:
U pthread_attr_setstacksize

The same on my pthread test program shows:
U pthread_attr_setstacksize@@GLIBC_2.1

Pthread test program below:
========================================================
#include <pthread.h>
#include <stdio.h>

void* thr_main(void*);

int main(int argc, char *argv[])
{
int num_threads = atoi(argv[1]);
int i;
size_t stacksize;

pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) {
printf("ERROR: pthread_attr_init\n");
}

// pthread_attr_getstacksize (&attr, &stacksize);
// printf("Default stack size = %d\n", stacksize);

if (pthread_attr_setstacksize (&attr, 2*1024*1024) != 0) {
printf("ERROR: pthread_attr_setstacksize\n");
}

pthread_t thr;
for (i=0; i < num_threads; ++i) {
pthread_create(&thr, &attr, thr_main, 0);
}

pthread_join(thr, 0);
}

void* thr_main(void* arg) {
while (1) {
sleep(10);
}
}
======================================================

Douglas C. Schmidt

unread,
Jan 9, 2007, 10:32:23 AM1/9/07
to Venkatraju, ace-...@cs.wustl.edu

Hi Venkat,

Thanks for using the PRF. Can you please try replacing
ACE_Thread::spawn() with the ACE_Thread_Manager::spawn() and see if that
works better?

Thanks,

Doug

> _______________________________________________
> ace-users mailing list
> ace-...@mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/ace-users

Robert Iakobashvili

unread,
Jan 9, 2007, 11:33:54 AM1/9/07
to Douglas C. Schmidt, ace-...@cs.wustl.edu
Hi,

On 1/9/07, Douglas C. Schmidt <sch...@dre.vanderbilt.edu> wrote:
>
> Hi Venkat,
>
> Thanks for using the PRF. Can you please try replacing
> ACE_Thread::spawn() with the ACE_Thread_Manager::spawn() and see if that
> works better?

What is your errno?
It may be a su allowed operation.

Sincerely,
Robert Iakobashvili,
coroberti %x40 gmail %x2e com
...................................................................
Navigare necesse est, vivere non est necesse
...................................................................
http://sourceforge.net/projects/curl-loader
A powerful open-source HTTP/S, FTP/S traffic
generating, loading and testing tool.

Venkatraju

unread,
Jan 9, 2007, 11:38:12 PM1/9/07
to Douglas C. Schmidt, ace-...@cs.wustl.edu
Hi Doug,

On 1/9/07, Douglas C. Schmidt <sch...@dre.vanderbilt.edu> wrote:
>
> Hi Venkat,
>
> Thanks for using the PRF. Can you please try replacing
> ACE_Thread::spawn() with the ACE_Thread_Manager::spawn() and see if that
> works better?

I see the same behaviour with ACE_Thread_Manager as well. I am looking at:
http://www.google.com/codesearch?hl=en&q=+pthread_attr_setstacksize+glibc+show:LJH_-2h738s:nT0XzExAMNQ:Pr2otuY6cWA&sa=N&cd=1&ct=rc&cs_p=http://gentoo.osuosl.org/distfiles/glibc-2.3.5.tar.bz2&cs_f=glibc-2.3.5/nptl/pthread_attr_setstacksize.c#a0
Wonder if the versioned symbol part has something to do with this? And
the output
from "nm" I mentioned in my last mail:

"nm libACE.so.5.5.0 | grep stacksize" shows:
U pthread_attr_setstacksize

The same on my pthread test program shows:
U pthread_attr_setstacksize@@GLIBC_2.1

I built ACE using the standard configure, make, make install on FC5. I
also noticed
the same problem sometime back on FC4 as well. Anyone else see the same problem
on FC4/FC5?

Thanks,
Venkat

Venkatraju

unread,
Jan 9, 2007, 11:43:39 PM1/9/07
to Robert Iakobashvili, ace-...@cs.wustl.edu
Hi Robert,

On 1/9/07, Robert Iakobashvili <coro...@gmail.com> wrote:
> Hi,


>
> On 1/9/07, Douglas C. Schmidt <sch...@dre.vanderbilt.edu> wrote:
> >
> > Hi Venkat,
> >
> > Thanks for using the PRF. Can you please try replacing
> > ACE_Thread::spawn() with the ACE_Thread_Manager::spawn() and see if that
> > works better?
>

> What is your errno?
> It may be a su allowed operation.

Spawning the thread succeeds - errno is not set. I disabled selinux as well
and ran it as root and still see the same problem. Also, the pthread program
runs just fine even as a regular user.

Thanks,
Venkat

Krishnakumar B

unread,
Jan 10, 2007, 12:11:56 AM1/10/07
to Venkatraju, ace-...@cs.wustl.edu
Hi,

On Tue, 09 Jan 2007 09:28:29 AM -0600, Venkatraju wrote:
> Hi,
>
> I am not able to set stack size for ACE_Threads. More details in the PRF
> below. Please let me know if you need any additional information.

[...]

> The above test program is built and run. I monitor the stack size using:
> "ps -eo pid,size,cmd | grep -i thread"

The "size" output formatter to ps prints out the memory size of the process
in kilobytes. Why do you think that the MEMORY SIZE of a process as
reported by ps is the same as the STACK SIZE of a SINGLE thread within that
process? Modify your program to print out the stack size within the newly
spawned thread using pthread_attr_getstacksize().

Since ACE_OS::thr_create calls into pthread_attr_setstacksize(), there
should be no difference in the results of pthread_attr_getstacksize()
output.

-kitty.

--
Krishnakumar B <kitty at dre dot vanderbilt dot edu>
Institute for Software Integrated Systems, Dept. of EECS, Vanderbilt University

Venkatraju

unread,
Jan 10, 2007, 4:43:25 AM1/10/07
to Krishnakumar B, ace-...@cs.wustl.edu
Hi,

On 1/10/07, Krishnakumar B <ki...@dre.vanderbilt.edu> wrote:
> Hi,
>
> On Tue, 09 Jan 2007 09:28:29 AM -0600, Venkatraju wrote:
> > Hi,
> >
> > I am not able to set stack size for ACE_Threads. More details in the PRF
> > below. Please let me know if you need any additional information.
>
> [...]
>
> > The above test program is built and run. I monitor the stack size using:
> > "ps -eo pid,size,cmd | grep -i thread"
>
> The "size" output formatter to ps prints out the memory size of the process
> in kilobytes. Why do you think that the MEMORY SIZE of a process as
> reported by ps is the same as the STACK SIZE of a SINGLE thread within that
> process? Modify your program to print out the stack size within the newly
> spawned thread using pthread_attr_getstacksize().
>
> Since ACE_OS::thr_create calls into pthread_attr_setstacksize(), there
> should be no difference in the results of pthread_attr_getstacksize()
> output.
>
> -kitty.

Ok - I wasn't quite precise in my first mail. I don't expect the output of ps
to be the stack size of one thread. When I increase the thread count by 1 in my
program, the virtual memory usage of the program increases by about 10MB.
I think most of this is the stack size for the new thread - so I am trying to
see why that does not take effect.

Quoting from my first mail:
> The stack size printed when run with 4 as the first argument is 41260K.
> When the argument is 8, it is 82240K etc.

So, that is ~40M increase for 4 threads. I think that is because of a 10M
increase PER THREAD.

Is there ACE API for getting a running thread's stack size?
pthread_attr_getstacsize
needs a pthread_attr_t. Please let me know and I will try that.

Thanks,
Venkat

erta...@gmail.com

unread,
Feb 15, 2007, 2:23:19 AM2/15/07
to
Hi,

I have mentioned this problem way back with ACE version 5.4.10.

http://groups.google.com.tr/group/comp.soft-sys.ace/browse_thread/thread/4a34783c99a25ed2/4f08b47d7bc9fa3b?lnk=gst&q=user+thread+stack&rnum=6&hl=tr#4f08b47d7bc9fa3b

I am currently using ACE 5.5 and Fedora 4. (ACE installed with
configure, make, make install )
The problem still exists and is exactly the same as yours.

I hope this is resolved as soon as possible.

Ertan Deniz


Douglas C. Schmidt

unread,
Feb 15, 2007, 8:23:41 AM2/15/07
to erta...@gmail.com, ace-...@cse.wustl.edu
Hi Ertan,

The fastest way for this to get resolved is for you to step through
the source code in a debugger and figure out what's going on. If you
find the source of the problem is in ACE please send us patches to fix
it.

Thanks,

Doug
--
Dr. Douglas C. Schmidt Professor and Associate Chair
Electrical Engineering and Computer Science TEL: (615) 343-8197
Vanderbilt University WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203 NET: d.sc...@vanderbilt.edu

Steve Huston

unread,
Feb 15, 2007, 9:44:44 AM2/15/07
to erta...@gmail.com, ace-...@cse.wustl.edu
> -----Original Message-----
> From: ace-user...@cse.wustl.edu
> [mailto:ace-user...@cse.wustl.edu] On Behalf Of Douglas
> C. Schmidt
> Sent: Thursday, February 15, 2007 8:24 AM
> To: erta...@gmail.com; ace-...@cse.wustl.edu
> Subject: Re: [ace-users] Thread stack size does not take effect
>
>
> Hi Ertan,
>
> >I have mentioned this problem way back with ACE version 5.4.10.
> >
> >http://groups.google.com.tr/group/comp.soft-sys.ace/browse_th
read/thread/4a34783c99a25ed2/4f08b47d7bc9fa3b?lnk=gst&q=user+thread+st
ack&rnum=6&hl=tr#4f08b47d7bc9fa3b
>
> >I am currently using ACE 5.5 and Fedora 4. (ACE installed with
> >configure, make, make install )
> >The problem still exists and is exactly the same as yours.
>
> >I hope this is resolved as soon as possible.
>
> The fastest way for this to get resolved is for you to step through
> the source code in a debugger and figure out what's going on. If
you
> find the source of the problem is in ACE please send us patches to
fix
> it.

... Or take advantage of the services of one of the ACE support
companies who'd be more than happy to relieve you of that debugging
effort.

-Steve

--
Steve Huston, Riverace Corporation
New Support options to help you with ACE!
See http://www.riverace.com/support.htm

erta...@gmail.com

unread,
Feb 28, 2007, 2:58:32 PM2/28/07
to

> > > The ACE_Thread version does not seem to takestacksizes below 10MB?

>
> > > Not sure if this is helpful:
> > > "nm libACE.so.5.5.0 | grep stacksize" shows:
> > > U pthread_attr_setstacksize
>
> > > The same on my pthread test program shows:
> > > U pthread_attr_setstacksize@@GLIBC_2.1
>

By consentrating on this info I finally managed to identify and solve
the problem.
ACE library was strangely calling an older pthread_create which
assumed
that pthread_attr_t does not contain stacksize etc...

It was simply ignoring the stacksize attribute.

The problem is in the link stage. In the link command line -lpthread
must come after the object files (or .a libraries) that
use them on the link line.

The solution came from the following places;

https://mail.gna.org/public/xenomai-core/2005-12/msg00034.html
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=145941

The only thing we need to do is change the file:

ACE_wrappers/ace/Makefile.am

Old LDFLAGS:

libACE_la_LDFLAGS = \
-release @ACE_VERSION_NAME@

New LDFLAGS:

libACE_la_LDFLAGS = \
-release @ACE_VERSION_NAME@ -lpthread


Tried and verified that passing the stacksize argument works.

Sorry that I couldn't send this as a diff patch.

Ertan Deniz

0 new messages