# multithreading lock issue



## sudhirgarg (Jul 16, 2010)

what are the compile options for multithread program on bsd with pthread library.

I am using pthread lib for my program. It has 10 threads. It sometimes getting hanged and stack trace for thread seems to be not right. I suspect some issue with the way I am building trace looks like this. please let me know what I should I make sure from build perspective while running multithread program on bsd.

PLEASE NOTE that Same program runs fine on linux


stack trace



```
(gdb) bt                                                                             
#0  0x2808f035 in __error () from /lib/libthr.so.3                                   
#1  0x2808ead0 in __error () from /lib/libthr.so.3                                   
#2  0x28226220 in ?? ()                                                              
#3  0x0000000d in ?? ()                                                              
#4  0x00000000 in ?? ()                                                              
#5  0x00000000 in ?? ()                                                              
#6  0x00000000 in ?? ()
#7  0x00000005 in ?? ()
#8  0xbf1f6f18 in ?? ()
#9  0x280895a1 in pthread_rwlock_init () from /lib/libthr.so.3
Previous frame identical to this frame (corrupt stack?)
(gdb) info thread
  10 Thread 0x28201100 (LWP 100511)  0x2808f037 in __error () from /lib/libthr.so.3
  9 Thread 0x28201200 (LWP 100204)  0x2808f037 in __error () from /lib/libthr.so.3
  8 Thread 0x28201300 (LWP 100292)  0x2808f037 in __error () from /lib/libthr.so.3
  7 Thread 0x28201400 (LWP 100334)  0x2808f037 in __error () from /lib/libthr.so.3
  6 Thread 0x28201500 (LWP 100468)  0x2808f037 in __error () from /lib/libthr.so.3
  5 Thread 0x28201600 (LWP 100653)  0x2808f037 in __error () from /lib/libthr.so.3
  4 Thread 0x28201700 (LWP 100858)  0x2808f037 in __error () from /lib/libthr.so.3
  3 Thread 0x28201800 (LWP 100903)  0x2808f037 in __error () from /lib/libthr.so.3
  2 Thread 0x28201900 (LWP 101086)  0x2808f037 in __error () from /lib/libthr.so.3
* 1 Thread 0x28201a00 (LWP 101123)  0x2808f035 in __error () from /lib/libthr.so.3
(gdb) thread 3
[Switching to thread 3 (Thread 0x28201800 (LWP 100903))]#0  0x2808f037 in __error ()
   from /lib/libthr.so.3
(gdb) bt
#0  0x2808f037 in __error () from /lib/libthr.so.3
#1  0x2808ead0 in __error () from /lib/libthr.so.3
#2  0x28304070 in ?? ()
#3  0x0000000d in ?? ()
#4  0x00000000 in ?? ()
#5  0x00000000 in ?? ()
#6  0x00000000 in ?? ()
#7  0x00000005 in ?? ()
#8  0xbf3f8f18 in ?? ()
#9  0x280895a1 in pthread_rwlock_init () from /lib/libthr.so.3
Previous frame identical to this frame (corrupt stack?)
(gdb)
```


----------



## sk8harddiefast (Jul 16, 2010)

Well i don't know a lot about programmning but when i tried to compile dwm he didn't do it with default systems compiler. When i tried a newer version of gcc compiler he did it.
Install gcc45 from ports and *gcc yourfile.c CC=gcc45* ? (i guess your are writing C programm)
*Maybe has nothing to do!* I don't know even in what language you write the program.
Just an idea.


----------



## Alt (Jul 16, 2010)

Maybe you must use pthread_attr_setstacksize to increase stack size? It may differ between diffirent os..


----------



## sudhirgarg (Jul 16, 2010)

@Alt

I tried with increasing the stack size. By default on BSD it was 1MB I increased it to 16 MB still have the same problem.

The program is in c.


----------



## expl (Jul 16, 2010)

What code/program are you building? Cant really help you without seeing the source and the way you build it.


----------



## sudhirgarg (Jul 16, 2010)

```
gcc -g -Wall -D_REENTRANT -pthread   -c stubs.c
gcc -g -Wall -D_REENTRANT -pthread   -c utils.c
gcc -g -Wall -D_REENTRANT -pthread   -c teid_mgmt.c
gcc -g -Wall -D_REENTRANT -pthread   -c sp_test.c
```


`gcc -o jrcmsptest stubs.o utils.o teid_mgmt.o sp_test.o -lpthread`
Is there something wrong in compilation

Is there any other system limits that I should look at. Thread stack size increase didn't work.  for user thread we do specify the stack size in thread attribute, how can we increase the stack size of main thread.

Sorry can't post the actual code since it has legal implications.


----------



## qsecofr (Jul 16, 2010)

Are you sure the error is due to stack size?  Not being familiar with gdb or pthreads on unix I'd guess the error occurred in pthread_rwlock_init().  (I had done a few pthread C programs on another platform)  But I'd be willing to bet there's an rc return code whose value might help shed some light on whichever pthread library function failed.


----------



## Alt (Jul 17, 2010)

You may try to recompile kernel with increased KSTACK_PAGES, but i dont know will this help or not


----------



## expl (Jul 18, 2010)

I would guess there is some short of memory mismanagement error happening in the application (buffer overflow) and the reason it works on linux is because memory is aligned differently.


----------

