Programming :: Rules To Set The Pthread Stack Size - Compute The Memory Needed By Each Thread?

Jul 26, 2010

i have an application that launches several pthreads, i know that the default size used by Linux is 8Mb for each pthread. However i would like to optimize the total memory usage by my application by decreasing the default stack size of each pthread to the needed resources. My questions:

- Are there any rules to set the pthread stack size.
- How to compute the memory needed by each thread.
- Is the malloc call inside a thread counted from the stack size of the same pthread?

View 2 Replies


ADVERTISEMENT

Programming :: Increasing Thread Stack Size?

Jan 23, 2011

I seem to only be able to set my stack size on my linux server to 15000. If I increase it to 20000 I get a Segmentation Fault. how I can get the linux OS to increase the stack size? Code: threadRet |= pthread_attr_setstacksize( &m_ThreadAttributes, 15000 );

View 8 Replies View Related

Programming :: Why The Thread Stack Size Cannot Be Changed When Calling In A Dynamic Library

Jan 5, 2011

Why the thread stack size can not be changed after calling pthread_attr_setstacksize & pthread_create in a dynamic library? Detail: I write a file thread_factory.c and plan to build it and produce a dynamic library (libthread_factory.so) In the thread_factory.c , there is a routine

[Code]....

And after this, there is application, it will call fct_thread_create(STACK_SIZE_256KB), and then call pthread_attr_getstacksize(), but the stack size return always be a fixed value 0xa01000. (I tried this on Fedora12) But if I build the application source code with the file thread_factory.c directly, the stack size return is right as my expect. I checked the source code of glibc about the routine pthread_create() as below:

[Code]....

View 7 Replies View Related

Ubuntu Servers :: How To Decrease Thread Stack Size

Feb 5, 2010

Desperate to reduce RAM usage of my tiny VPS running Ubuntu 9.04 and Apache2.2.11, here I saw that:
On Linux, each child process will use 8MB of memory by default. This is probably unnecessary. You can decrease the overall memory used by Apache by setting ThreadStackSize used by Apache by setting ThreadStackSize to 1MB in.

So I tried to give the suggestion a try. But when I append:
ThreadStackSize 1000000
in my /etc/apache2/httpd.conf <IfModule mpm_prefork_module> directive, and restarted apache, it failed with this message:
Invalid command 'ThreadStackSize', perhaps misspelled or defined by a module not included in the server configuration

So I figured out that the relevant modules are neither enabled nor available on apache2. Now I am wondering whether there is a way to decrease the ThreadStackSize without the need to compile apache from source? If not, what should I do?

View 1 Replies View Related

Programming :: Suspend/resume A Thread When Using Pthread.h?

Dec 14, 2010

I want to suspend/resume a thread. The library I am using is pthread.h.I am also running my application on linux.Is there any function in pthread. let me suspend a thread temporary?I have read a document in which it was mentioned thatthread does not support suspend/resume

View 4 Replies View Related

Programming :: Thread Stack Using Pthread_attr_setstackaddr()?

Sep 22, 2010

When I set the stack base address of the child thread using the POSIX library function "pthread_attr_setstackaddr()", I am unable to access the memory contents of its parent. The data-structures that are created on the HEAP of its parent using malloc() are either getting destroyed or unaccessible when moving to the context of the child thread. These data-structures are being passed as an argument to the child thread.Even if I make these variables global then also it is not working.pthread_attr_setstacksize(tattr, ...);stackbase = (void *) malloc(...);pthread_attr_setstackaddr(tattr, stackbase);But when I create the child thread without setting its stack base address using that pthread_attr_setstackaddr(), then it is able to access the parent's memory contents.

View 1 Replies View Related

Programming :: Pthread Not Release Memory

Jan 1, 2011

I have faced a problem with my code (a small tcp server). After the thread returns, the memory not decreases, but when a new connection is made, memory not increases and the new connection initialize a new thread with a same thread id of the previous thread. When two connections are made at same time, two thread ids are created and when the respective threads returns the memory not decreases. The Valgrind indicates that not memory leak occurs, the pointers are released. Indeed, more memory are allocate when new thread id is created. i used gcc and debian.

[Code]....

View 1 Replies View Related

Programming :: Pthread Memory Not Being Freed?

Apr 19, 2010

I have an application that has pretty large memory profile. The general program flow is as follows:

Code:
main:
do 10 times:

[code]....

View 9 Replies View Related

Programming :: Pthread - Take String From The Command Line And Creates A Thread To Print The String

May 3, 2011

I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.

[Code]....

One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?

Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.

View 6 Replies View Related

Programming :: Why The Stack Size Limit

May 1, 2011

Why is it in Linux that there is a stack size set by default? And why is it so small? (My system is set to 8192 kbytes.) And why is there a default limit on the stack size when the max memory and virtual memory size are, by default, unlimited? (Aren't they both fed from the same place ultimately?)

Reason I ask: I want to use recursive functions in my programming a lot more. Problem is, if the language (or implementation) doesn't happen to support tail-call recursion, then I can be pretty well certain that the first huge problem that gets thrown at my function is going to kill my program because the stack size limit is going to be quickly reached. Obviously, I can change the stack size limit for my own computers, but it doesn't feel so great knowing that most of the people who copy and execute my code will have probably have overlooked this. Anyway, does anyone know: is this small default stack size limit just one of those historical artifacts, or is there some technical reason for it?

View 5 Replies View Related

General :: 1:1 - What's Meant By There Is Kernel Level Thread For Each Pthread Created

Mar 11, 2011

I have gone thorugh some documents about pthread (NTPL ) in linux 2.6 kernel. As per that linux uses 1: 1 threading model and for each user level thread there is kernel level thread. Pthread_create uses clone system call to create a LWP and the kernel could treat that as a LWP and do scheduling and all .( different from linuxthread). My question is what's meant by there is kernel level thread for each pthread created. Can I see the kernel level thread if I call pthread_create using ps .

What exactly meant by 1:1 .I mean for each user level thread there is kernel level thread . If I make a system call from a thread does the OS services that action via kernel thread ( created using kernel_thread () or some other way ) internally ..

View 1 Replies View Related

Programming :: How To Bind Thread To Specific Thread In Multithread Application?

Dec 25, 2010

I am going to use "pthread_setaffinity_np" to bind a thread to a specific core. My application has two threads. I have used mutex to assign a specific id to each thread and then bind that thread to a core different from another core. but it seems that the os assigns both thread to one core.What should I do to bind each thread to a specific core?

View 4 Replies View Related

General :: How To Get Stack Size Of Running Process?

Apr 17, 2011

Can anyone tell me that how to get information about stack, allocated by kernel to a running process? for this ,is there any api function,any system call is available in ubuntu 8.04 ?

View 2 Replies View Related

Programming :: Realloc(): Invalid Next Size / Getting Error With Reallocate Memory In MakeDSt Function For DSt->SArray?

Jul 19, 2011

I wrote a test program for learning usage of realloc() and I thin I did everything right but I get this error exactly with my 4th time that while tries to reallocate memory in MakeDSt function for DSt->SArray:

Quote:

realloc(): invalid next size

this is my complete code :

Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct DRA
{
code....

View 2 Replies View Related

Software :: Find The Size Of A Stack When A Process Is Running?

Dec 6, 2010

How do we find the size of a stack when a process is running?

View 1 Replies View Related

Red Hat :: Find The Dynamic Stack And Heap Size Of A Running Process In Rhel?

Aug 26, 2010

I am trying to find the dyanmic heap size and stack size of a running process in rhel5.5 and rhel6.I read that the 23rd parameter in the file /proc/pid/stat gives the heap size.Can you elaborate more on this.Also is there any other way to do this?

View 5 Replies View Related

Software :: Bash Console - Shell - STACK Size: 98222 [0x7f665dbe4e00 0x7f665db25090]

May 14, 2010

i'm getting messages like these in my bash console

Code: STACK size: 98222 [0x7f665dbe4e00 0x7f665db25090] and i'm not quite sure what they mean, so far it looks it's related to the shell stack limit set by ulimit, however i've tried to change it (increasing it) however this message still persists.

View 9 Replies View Related

Server :: Calculate Memory Available If Needed On A System?

Jul 16, 2010

I have set swappiness to 0:

# sysctl vm.swappiness
vm.swappiness = 0

According to various sources, this should mean that applications have priority over file chaches, and swap should only be used when the applications themselves need more memory than is physically available. So I naively took the value free provides in the '-/+ buffers/cache' line as 'free' as the amount of memory to be available on the server. Unfortunately this is not even close to true: On a server with 20GB RAM, memory utilization by this measure never reached 50%, yet the system swaps.

I then figured out that I could use 'sync; echo 3 > /proc/sys/vm/drop_caches' to drop cached stuff. I was very surprised to still have 12.5 GB cached data after doing that. I am figuring that it's those 12.5 GB which force the system to start swapping. I also tried to use /proc/meminfo to figure out how that cached memory is used (by comparing its content before and after dropping caches). However, I don't see the correlation between the numbers provided there and what part of the cache can be dropped.

The closest match seems to be the 'Mapped' line, which was 10GB. I am pretty sure that being mmapped keeps the kernel from dropping cache. However, the value is 2.5 GB less than the cache which can't be dropped. So it is not the whole answer. What I am looking for is some way to determine how much memory the kernel could provide by dropping stuff if he needs to because of memory pressure. Is there maybe a way to simulate drop_caches without actually doing so?

The amount of potentially available memory does not have to be scientifically correct, but the number should at least be always in the right ballpark, which right now, it ain't... The point here is that it's a productive system. Sy doing stuff like dropping caches or filling memory until the system starts to swap is not a permanent solution to figure out the value. By the way, it turned out that postgres was the culprit in this concrete case, stopping it made dropping all caches possible, but that does not answer the general question of how to estimate available memory...

1. Is my assumption correct that I can subtract 'Mapped' from the freeable cache memory completely?

2. Where could the other 2.5 GB be used?

3. Is there a way to get a better guess of how much memory the system can free if necessary, before swap has to be used?

View 1 Replies View Related

Programming :: Remote Function With Pthread?

May 22, 2010

I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first).

Code: #include <pthread.h>
#include "starter.h"
#include "UI.h"
Page* MM;

[Code]....

View 6 Replies View Related

Programming :: Signal Handling In Pthread?

Mar 12, 2011

I have created a pthread, and installed a signal handler inside that, same way as we do in main( ) function. The thread's signal handler is a separate function. Surprisingly, it is not working, that is the thread's signal handler is not able to catch signals. Here is the code:

Code: #include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <signal.h>
typedef struct data

[Code]...

View 1 Replies View Related

Programming :: Portable Pthread Library Out Of 10 Distros?

Mar 10, 2011

im writing a cross-platform software (linux/solaris/mac/bsd) so i was wondering, how portable is pthread library? out of 10 linux distros, how many will have it by default? and does it exists on mac/solaris/bsd by default? or user will have to install it?

View 6 Replies View Related

Programming :: Pthread Mapping From Compiler To Kernel?

Aug 20, 2010

I'm trying to figure out how pthreads are mapped from the compiler to the Linux kernel. The pthread prototypes are found in a compiler header file (pthread.h), yet the kernel would be responsible for scheduling the threads. So, how does the compiler resolve the pthread symbols at compile time?

View 1 Replies View Related

Programming :: Pthread And Mutex With Short Unlock Time?

Jun 15, 2010

I am wondering if pthread could make that a single thread keeps the "mutex" all the time if the time it remains unlocked is very small.

thread1
{
while (1)
{
lock; do_task(); unlock();

[code]...

I experiment the thread2 never getting access to the mutex and never printing the nice message. I would expect that once thread2 calls "lock", it would get the mutex as soon as thread1 calls unlock() but it does not seem to be the case. If I add a sleep of some microseconds (100) in thread1 after unlocking the mutex, it solves the problem.

Does anyone know if this behaviour is normal? Is there a way to configure my mutex so that thread2 receives it when unlocked?I use

pthread_mutexattr_settype(&att, PTHREAD_MUTEX_RECURSIVE_NP);
pthread_mutex_init(&handle, &att);

to create my mutex. I am running ubuntu 9.04

View 3 Replies View Related

Programming :: Use Pthread Scheduling Policy Without Root User?

Jan 12, 2011

I am working on a large program in C to run on Puppy Linux. I have multiple pthreads running. I want to be able to set the pthread SCHED_POLICY and priority in my program but I want a user to be able to run the program without root privilege.
Using a sticky bit and root ownership gives the user too much power because they will be able to write and compile their own scripts. Is there a way to use 'sudo' when I set the thread parameters from my program or something like this?

View 1 Replies View Related

Programming :: Pthread - Optimize Computing Function / Loop With Threads?

Sep 4, 2010

I have to compute prime numbers with threads in C. So I choose the algorithm "Sieve of Eratosthenes" and I tried to create 2 threads, but I don't know how to optimize my computing function with threads I beg for help. This is my function:

[Code]...

but it seems like the both of the threads are calculating the same function twice? Is it possible to be optimized or not?

View 7 Replies View Related

Ubuntu :: Compiz Window Rules - Maximize Size Below Panel?

Jul 6, 2011

I can't stand looking at the ugly, off-center, non-themed maximize/minimize/close buttons in the maximized global menu. Is it possible to set a window to maximize *below* the top panel? Or at least to have its set fixed size be its fixed size when not maximized?

Using Compiz window rules I've been able to set a fixed size in some applications (Opera, for example), but whenever I open them, the window automatically opens as maximized. When I un-maximize, it reverts to whatever size it wants, and having to resize my windows all the time is a pain.

View 1 Replies View Related

Programming :: Socket Server Using Pthread Doesn't Wait For Accept() Properly?

Apr 19, 2010

I'm building a simple(?) socket server using threads to serve up a few requests. The spec is such that I have to listen to three ports at once, so I decided to use pthread to create three separate threads that would wait for connections, then spawn new threads to handle them.

The problem is that when I do this, for some reason the program never enters the wait loop and instead terminates (All three threads did get created since the messages get printed properly.) It gets to the line which prints "???", but not the line after the accept() call.I don't see an open port when I check for one either so I'm 99% sure they're terminating.Basically I have a main() method which has three calls to pthread_create, which should result in three threads being run that all wait for connections (listenOnPort). After each thread creation I print some info to make sure it's actually being created.

By the way, when I just run listenOnPortwithout threading, the server appears to enter the loop correctly and seems to be waiting for requests. It's only when I run the functions as threads that the problem seems to happen.The source is attached below. Any help will be appreciated. Much of the code is borrowed from a website (I can't post it because I am new here.) You need not worry about the handler_ methods because those are just methods that are run by the threads themselves.

Also--the original source was in C and I changed it to C++. Should I just use C?
server.h Code: /*
* server.h

[code]....

View 1 Replies View Related

Programming :: Unix Programming - Single Thread Server Can Support Exactly 2 Clients At Once

Sep 28, 2010

A simple TCP based chat server could allow users to use any TCP client (telnet, for example) to communicate with each other. For this question you should consider a single process, single thread server that can support exactly 2 clients at once, the server simply forwards whatever is sent from one client to the other (in both directions). Your server must not insist on any specific ordering of messages as soon as something is sent from one client it is immediately forwarded to the other client. As soon as either client terminates the connection the server can exit

View 4 Replies View Related

Programming :: Setup A Stack (1kB) For My Module In C?

Sep 6, 2010

I need to call some other functions in "int init_module(void)" and module. So I need a stack. How can I setup a stack (1kB) for my module in C?

View 11 Replies View Related

Programming :: View Stack Of Process?

Mar 1, 2011

If I issue the following and the process doesn't quit, is there a way to view what it's doing with the SIGTERM signal on the stack? Is this done via the pstack command?kill -s SIGTERM <PID>

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved