This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Strange error locking a pthread mutex...


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]