cancel
Showing results for 
Search instead for 
Did you mean: 

pthread_mutex

 
Highlighted
katakura
Occasional Contributor

pthread_mutex

Hi

we are having problem when our program start on HP-UX 11.23 itanium.
Our program is ported from 11.0 and it is 32bit program running under aries.

The program is using pthread_mutex library to be thread-safe under multithreading.
There are two threads Thread A and B.
The problem is... before finishing mutex initialization by pthread_init on Thread A, Thread B accesses the
exclusive area on thread A , and get Access Violation.

The program create thread A and B in order, but when it is executed on fast processor,
thread B's execution is too fast. I am guessing that is why this problem is occurred.
This problem is only happens on application using initialization of pthread_mutex.

When I encounter this problem, should I put "sleep" on thread B and wait for a second?
If anyone know if OS patch addressing above problem, let me know.
1 REPLY 1
Highlighted
Dennis Handly
Acclaimed Contributor

Re: pthread_mutex

>before finishing mutex initialization by pthread_init

You should initialize mutexes before you start threads.
Or initialize them statically:
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

>If anyone know if OS patch addressing above problem

Patches don't usually address programming errors.