Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mutex lock twice

527 views
Skip to first unread message

Djails

unread,
Jan 10, 2001, 10:36:42 AM1/10/01
to
I wrote an application which deals with sockets. To avoid accept()'s
blocking state, I choose to use the pthread library.
It works fine except that , .... my process grows in memory, and about 1
hour after I ran it, -> Segmentation Fault.
So I'm wondering if that problem could originate from this: Sometimes,
the same mutex is locked (or unlocked) two or more times. Here's my
question:
What happen if the same mutex is locked 2 or more times without being
unlocked between each lock ?
N what if a mutex is unlocked several times without being lock between
each ?
Has it anything to do with memory ?
Thanx for your answer


Sent via Deja.com
http://www.deja.com/

Lie-Quan Lee

unread,
Jan 11, 2001, 1:30:15 PM1/11/01
to
On Wed, 10 Jan 2001, Djails wrote:

> I wrote an application which deals with sockets. To avoid accept()'s
> blocking state, I choose to use the pthread library.
> It works fine except that , .... my process grows in memory, and about 1
> hour after I ran it, -> Segmentation Fault.
> So I'm wondering if that problem could originate from this: Sometimes,
> the same mutex is locked (or unlocked) two or more times. Here's my
> question:
> What happen if the same mutex is locked 2 or more times without being
> unlocked between each lock ?

The behavior of locking mutex twice is depending on the mutex you used.
Ususally OS provides several kinds of mutexes, fast, recursive, and error-
checking mutex.(Some OS may only provides fast mutex.) Locking fast mutex
twice in the same thread is a deadlock. Locking recursive mutex twice in
the same thread means you need unlok it twice. Locking erro-checking mutex
in the same thread will reurn immediately with an error. You had better
consult the manual in you system.

> N what if a mutex is unlocked several times without being lock between
> each ?

I do not know. But why do not you avoid that by right programming logic?
what do you think?

***************************************************
Rich Lee (Lie-Quan)
Lab for Scientific Computing
University of Notre Dame
Email : ll...@lsc.nd.edu
Tel : 219-631-3906 (Office)
HomePage: http://www.lsc.nd.edu/~llee1/
***************************************************


0 new messages