Strange error locking a pthread mutex...

Bert Wesarg bert.wesarg@googlemail.com
Thu May 22 21:11:00 GMT 2008


On Thu, May 22, 2008 at 6:20 PM, Kris van Rens
<krisvanrens.list@gmail.com> wrote:
> Hi there,
>
> I'm experiencing peculiar problems using a pthread mutex in my
> program. Let me try to explain the setup of the program:
>
> There is a main thread which initializes a recursive mutex for use
> within (multiple) event threads running along the main thread, the
> mutex is used for (what a surprise) outlining a critical section.
>
> Here is a diagram (plaintext, ASCII-art):
>
> +------------------+
> | main() thread    |
> +------------------+
> | ...              |
> | initialize mutex |
> | ...              |
> | spawn threads ---+-------------+------------------------+-------------//
> | ...              |             |                        |
> =                  =    +------------------+     +------------------+
> +------------------+    | event thread1    |     | event thread2    |
>                        +------------------+     +------------------+
>                        | ...              |     | ...              |
>                        | lock mutex       |     | lock mutex       |
>                        | <critical stuff> |     | <critical stuff> |
>                        | unlock mutex     |     | unlock mutex     |
>                        | ...              |     | ...              |
>                        +------------------+     +------------------+
>
> The mutex variable is declared globally and initialised in the main thread.
>
> ---(globally)
> pthread_mutex_t CritSec;
> ---
>
> The initialisation of the mutex is being done as follows:
>
> ---
> pthread_mutexattr_t mutexattr;
>
Just guessing: no pthread_mutexattr_init()!

> // Set the mutex as a recursive mutex
> pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
>

Bert



More information about the Libc-help mailing list