Hi, What about getting stack pointer in the beginning of the thread and calculating offset to current SP internally?
On 10/8/07, Mike Kemelmakher <[EMAIL PROTECTED]> wrote: > > Hi , > > Oron Peled wrote: > > On Sunday, 7 בOctober 2007, Mike Kemelmakher wrote: > > > >> Hi, > >> > >> The pthread_attr_getstacksize() and pthread_attr_setstacksize() > >> functions, respectively, shall get and set the thread _*creation*_ > >> stacksize attribute in the attr object. > >> > > > > AFAIK, in terms of the pthead *API*, the creation size is the *only* size. > > This is because POSIX threads are implemented on many platforms, including > > non-Unix, non-MMU ones. That's why there is a standard attribute to set > > the stack size, while you don't have such a parameter for fork(). > > > > I must admit I didn't know Linux actually had a growing stack threads > > and it seems to me that they are a Linux extension -- > > For the Linux kernel a thread is a task like any other process and can > > easily have its stack mem-mapped to some private pages to implement this > > feature. Of course other Unices *may* implement it in a similar way. > > > > > >> What i need is current stack size of a running thread. My problem is > >> that i have a thread with constantly growing stack ( i can see it via > >> /proc/PID/smaps ). > >> > > > > Unless someone added a linux-specific API for this, you may have to > > revert to /proc/PID/smaps parsing :-( > > > > > >> Thread uses some functions from a proprietary shared library. I need to > >> know when the stack size of the mentioned thread reaches RLIMIT_STACK > >> so i can safely restart that thread before it crashes. > >> > > > > The wonders of proprietary code. You cannot fix the memory leak so > > you have to work around it... nice. > > > > Maybe the way to wrap it would be: > > 1. Create a watcher thread that would sample /proc/PID/smaps > > 2. Have this thread restart the problematic thread -- > > this is of course application specific. > > So when this library eventually get fixed, you can knife the ugly code out. > > > Indeed, thats what i do - juts there is no need for the watcher thread - > problematic thread monitors and restarts itself. > > 10x, > Mike > > P.S. It would be nice to add a linux-specific API for thread stack > monitoring. Moreover, there is API that can be extended to do this - > getrusage (2) . There is the field - ru_isrss - integral unshared > stack size - however linux does not maintain this field for some reason. > > > > > > > > > ================================================================= > To unsubscribe, send mail to [EMAIL PROTECTED] with > the word "unsubscribe" in the message body, e.g., run the command > echo unsubscribe | mail [EMAIL PROTECTED] > > -- Constantine Shulyupin Freelance Embedded Linux Engineer 054-4234440 http://www.linuxdriver.co.il/
