I'm working on an embedded C++ application running on Linux. I've recently encountered some really strange performance problems with pthreads.
My system has 8 threads passing information back and forth protected using a pthread mutex lock. When running my application stand-alone, thread performance is abysmally slow when taking a mutex lock. Locking and unlocking the mutex ~200 times takes 2.4 seconds on a 500 MHz ARM board, and longer on my 200MHz board.
The strange thing is that when I run my application under GDB, the application runs extremely quickly. The same block of code that took 2.4 seconds stand-alone takes about 2ms when GDB is running.
I've tested this behavior on 2 different ARM-based SBCs: one running Linux 2.4.26 with gcc 3.4.4 and glibc 2.3.2, and the other running Linux 2.6.21 also with gcc 3.4.4 and glibc 2.3.2.
After extensive testing, I'm suspecting that the problem lies in the pthreads library that happens to be the same version on both boards' toolchains. This would be unfortunate as my SBC supplier doesn't offer a very wide variety of toolchains for their board and I'm afraid that they'll all have this problem. Does anyone have any insight into what could be causing poor performance when not running under GDB?