kde-malloc pthread and system() hang
Sancho Dauskardt
sancho at dauskardt.de
Mon Nov 4 21:11:17 GMT 2002
Hi,
calling system() from a thread using the kde-code malloc occasionally hangs.
KDE_MALLOC=0 seems to solve the problem (but breaks other thing).
Adding the code below to any simple KDE3 app (KDevelop kde-sdi skeleton)
reproducibly causes this problem.
Running normally, is will start a master thread (to sepperate it from the
GUI) which in turn starts 8 threads, each constantly doing system("echo im
running..."). The master displays the success/failure counters of its slaves.
With KDE_MALLOC=0 all slave will be more-or-less equally outputing that
they are running.
With KDE_MALLOC=1 the slaves start to hang. Connecting gdb to such a thread
reveals that it's stuck in kde-cores malloc() of free().
Environment: out-of-the-box SuSE 8.0 & 8.1 (KDE 3.0.1 & 3.0.3).
Following code by it self (linked to kdecore, but no KApplication running)
will NOT produce the hang. The App also needs to do some memory allocation
(ie. opening / closing popup menus, etc.).
I managed to reproduce this running valgrind (takes ages), but didn't get
any complaints.
Is KDE_MALLOC=0 still 'supported' and supposed to work ??
- sda
----- snip ----
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
//
const int THREAD_CNT = 8;
pthread_t Threads[THREAD_CNT];
int ThreadOks[THREAD_CNT];
int ThreadFails[THREAD_CNT];
void *ThreadProc(void *arg)
{
int num = (int)arg;
for(;;){
char Str[256];
sprintf(Str,"echo \"%d(%d) live.\"\n",num,getpid());
if( 0 == system(Str) )
ThreadOks[num]++;
else
ThreadFails[num]++;
}
return (void *)0;
}
void *ThreadMain(void *arg)
{
int i;
for(i=0;i<THREAD_CNT;i++){
if( 0 != pthread_create(&Threads[i],0,ThreadProc,(void*)i) ){
printf("Thread %d create failed.\n",i);
return (void *)1;
}
}
fprintf(stderr,"Created %d threads.\n",i);
for(;;){
sleep(1);
for(i=0;i<THREAD_CNT;i++)
fprintf(stderr,"%d/%d
",ThreadOks[i],ThreadFails[i]);
fprintf(stderr,"\n");
}
return (void *)EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
...
pthread_t MainThreadID;
pthread_create(&MainThreadID,0,ThreadMain,(void*)0);
..
app.exec();
}
More information about the kde-core-devel
mailing list