top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How thread acquires mutex lock ?

+2 votes
913 views

Here my doubt is about acquire mutex lock.

Here pthread_mutex_t lock ; is also a global variable shared to threads. Accessing of this global variable (lock) will it be shame as accessing of other global variables ? If same, then don't we face same problem what we will face for other global variables ? if not ,how this is discriminated from other global variables ?

posted Dec 2, 2014 by Bheemappa G

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In the first go I saw the issue as real issue then I checked the structure of pthread_mutex_t which is as follows -

typedef struct {
    int __m_reserved;
    int __m_count;
    _pthread_descr __m_owner;
    int __m_kind;
    struct _pthread_fastlock __m_lock;
} pthread_mutex_t;

Now see the third field only owner is suppose to modify this variable to avoid the contention (this is my interpretation only not verified)

answer Dec 2, 2014 by Salil Agrawal
thanks salil. Ok still my doubt is say  pthread_mutex_t lock is global variable it will be stored in data segment .Just to change third field first we need to access lock variable right ? it seems basic but getting confused and cuerocity to know.thanks once again.
My interpretation is - this is a lock variable and you can change it only if you are __m_owner, if noone is the owner you can claim it and become the owner and then can change the value. So there would be no contention.
ok thank you .
Similar Questions
0 votes

I heard the term "worker thread" and other types of threads such as "system thread" and "user thread".
For me a thread is nothing but a lite weight process and multi-threaded design is chosen for a software development when there are multiple task in the application/system and those tasks can be executed independently.
I want to know when these different terms are used like worker thread, user thread and system thread ?

+2 votes

You are given two processes and each process is having four threads. One of the thread is having performance issue. How will you find out that thread which is having problem.

+1 vote

I wrote a multi-threaded program using pthread library, but I want execution of threads in a specific order.
What I have to do ?

+5 votes

Which one is better for which situation ??

...