![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HP-UX memory usage allocation | dehuang83 | HP-UX | 3 | 06-02-2007 03:40 AM |
| HP-UX memory usage allocation | dehuang83 | UNIX for Dummies Questions & Answers | 1 | 05-03-2007 01:40 AM |
| tar: Memory allocation failed | gfhgfnhhn | UNIX for Dummies Questions & Answers | 1 | 03-05-2007 11:23 AM |
| Static variables memory allocation | nathanmca | High Level Programming | 8 | 06-15-2005 12:57 AM |
| memory allocation | sagar | UNIX for Dummies Questions & Answers | 1 | 01-05-2002 11:53 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
threads and memory allocation
Hello!
First of all, forgive me for bad English. When I starts new thread (pthread_create), system allocates some memory for it (for example, for thread's stack). I wonder when does it deallocate this memory? The problem is that I have a program which sometimes creates new threads and sometimes deletes it. And memory used by my program always increases and never decreases (I use top utility to watch for my program behaviour). And I wonder is it my bug or standard behaviour. It seems my program stops threads which are not needed anymore, but memory doesn't decrease and after some time pthread_create says that it can't create new thread. I will really appreciate your help! P.S. The system is Solaris 5.10, if it matters. Last edited by prankster; 12-14-2005 at 10:22 AM.. |
|
||||
|
Some memory mgt strategies keep all the memory that brk() gets for the process.
Are you calling pthread_cleanup_push() & pthread_cleanup_pop() ? Under some circumstances: if the (void *) arg == 0 nothing will happen. ie., you leave junk behind. |
|
||||
|
1. Yes, I use cleanup_push and pop. Here is a part of my code:
Code:
void thread_cleanup(void* r) {
ARunnable* runnable = static_cast<ARunnable*>(r);
runnable->onClose();
delete runnable;
}
void* thread_function(void* r) {
CThread* th = static_cast<CThread*>(r);
ARunnable* runnable = th->target();
pthread_cleanup_push(thread_cleanup, static_cast<void*>(runnable));
try {
runnable->run();
}
catch (...) {
cerr << "error" << endl;
}
pthread_cleanup_pop(1); // 0
pthread_detach(th->thread()); // 1
pthread_exit(NULL); // 2
return NULL;
}
bool CThread::start() {
int e = 0;
if (0 != (e = pthread_create(&_thread, NULL, thread_function, static_cast<void*>(this)))) {
return false;
}
return true;
}
Also I have some misunderstanding about pthread_cleanup_push and pop technics. Does the system return control to the thread_function after calling thread_cleanup, if thread_cleanup is called not from the line 0? |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|