Date: Wed, 28 May 2003 10:24:58 +0300 From: Petri Helenius <pete@he.iki.fi> To: Daniel Eischen <eischen@pcnet5.pcnet.com> Cc: freebsd-threads@freebsd.org Subject: Re: malloc(): error: recursive call Message-ID: <3ED4644A.6050401@he.iki.fi> In-Reply-To: <Pine.GSO.4.10.10305271924010.1039-100000@pcnet5.pcnet.com> References: <Pine.GSO.4.10.10305271924010.1039-100000@pcnet5.pcnet.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Alright, here goes: (it's ugly cut&paste with inadequate includes and stuff but fails as expected) Uncomment the "extra" mutexes and it runs fine. Complied with: gcc -g -O2 -march=pentium -D_REENTRANT -D_THREAD_SAFE -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wconversion -Waggregate-return -Wstrict-prototypes -Wno-format -pedantic -Wno-long-long -c ttest.c gcc -static -g -O2 -march=pentium -D_REENTRANT -D_THREAD_SAFE -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wconversion -Waggregate-return -Wstrict-prototypes -Wno-format -pedantic -Wno-long-long ttest.o -o ttest -lkse libs: # ls -l /usr/lib/libkse* -r--r--r-- 1 root wheel 229156 May 24 14:57 /usr/lib/libkse.a lrwxr-xr-x 1 root wheel 11 May 24 14:57 /usr/lib/libkse.so -> libkse.so.1 -r--r--r-- 1 root wheel 121048 May 24 14:57 /usr/lib/libkse.so.1 -r--r--r-- 1 root wheel 243042 May 24 14:57 /usr/lib/libkse_p.a kernel: FreeBSD kompak.vuokselantie10.fi 5.1-BETA FreeBSD 5.1-BETA #7: Sat May 24 10:49:11 GMT 2003 root@kompak.vuokselantie10.fi:/usr/src/sys/i386/compile/EMTEST i386 # ./ttest free spin free spin free spin free spin free spin free spin free spin free spin free spin free spin free spin alloc spin free spin ttest in free(): error: recursive call Abort (core dumped) and the code: (has more stuff than it needs because it has some debugging built in) #include <stdio.h> #include <pthread.h> #define SLOTS 100000 void rommon_mutex_lock (pthread_mutex_t *mutex, int line) { int retvalue; int lastline; while (retvalue = pthread_mutex_lock (mutex)) { printf ("%d locking %lx failed, line %d (holder:%d)\n",getpid(),mutex,line,lastline); usleep (100000); } } static pthread_mutex_t foom; static char *foo[SLOTS]; live_poll_sharedmem() { while (1) { int i; printf ("alloc spin\n"); for ( i = 0 ; i < SLOTS; i++) { /* rommon_mutex_lock (&foom,__LINE__);*/ if (!foo[i]) { asprintf (&foo[i],"slot %d",i); } /* pthread_mutex_unlock (&foom);*/ } } } main() { static pthread_t smem_thread; pthread_mutexattr_t attr; int i; pthread_mutexattr_init (&attr); pthread_mutexattr_settype (&attr,PTHREAD_MUTEX_ERRORCHECK); pthread_mutex_init (&foom,&attr); pthread_create (&smem_thread,NULL,&live_poll_sharedmem,0); while (1) { printf ("free spin\n"); for ( i = 0; i < 100000; i++) { /* rommon_mutex_lock (&foom,__LINE__);*/ if (foo[i]) { free (foo[i]); foo[i] = NULL; } /* pthread_mutex_unlock (&foom);*/ } } } Daniel Eischen wrote: >On Wed, 28 May 2003, Petri Helenius wrote: > > > >>>And what does `ldd libnetsnmp.so.x`, `ldd libfoo.y`, show? >>> >>> >>They give empty replies. >> >> >> >>>What is `ldd yourexecutable` show? >>> >>> >>It?s usually linked static but if I remove the -static line it says: >> libnetsnmp.so.5 => /usr/local/lib/libnetsnmp.so.5 (0x2807f000) >> libcrypto.so.3 => /usr/lib/libcrypto.so.3 (0x280fe000) >> libpcap.so.2 => /usr/lib/libpcap.so.2 (0x28209000) >> libkse.so.1 => /usr/lib/libkse.so.1 (0x28225000) >> libc.so.5 => /usr/lib/libc.so.5 (0x28246000) >> >> >> >>>malloc is thread safe and we've been using it fine >>>with all our tests. I suspect you're using another >>>library that is using libc_r or something. >>> >>> >>malloc works for me with for example linuxthreads. So I do believe that >>the the trigger for malloc locking works, however looking at the code, >>spinlocks are implemented differently depending on which thread library is >>linked in. >> >> > >Also, you do need a relatively recent kernel. There are >a couple of flags in each thread's mailbox that the >kernel needs to recognize. This change was committed >to the kernel around April 21, 2003 > > >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3ED4644A.6050401>