Sponsored Content
Full Discussion: Mutex lock question
Top Forums Programming Mutex lock question Post 302334943 by cjjoy on Friday 17th of July 2009 12:36:33 AM
Old 07-17-2009
Mutex lock question

Hi all,
I have a scenario where I need to use the mutex locks. The mutex locks are working fine, but sometimes I am getting into the dead lock situation.

Below is the summary of my code :

MUTEX LOCK
performTask();
MUTEX UNLOCK.

In some cases I get into the situation where the thread is hung at performTask() function and never returns. When this happens the other threads which are waiting are blocked.

Please let me how can I kill the thread which is hung at performTask() function. Apart from using timed Mutex, is there a way I can return from performTask() function after waiting for a specified time?.


THanks
Joy
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mutex

Can anyone explain me what mutexes are in multithreading environment? (2 Replies)
Discussion started by: sagar
2 Replies

2. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies

3. AIX

pthread lock question

Is it possible that the function "pthread_cond_broadcast" block itself and the function "pthread_cond_wait" unblock in multi-threads programming ? The operating system is AIX 5.2, its maintenance level is : 5.2.0.4, VisualAge C++ 6.0. Thanks (0 Replies)
Discussion started by: Frank2004
0 Replies

4. Programming

How to handle mutex lock?

Hi, I have two tasks 'Read' and 'Write' which reads and writes on a file "abc.txt" respectively. Now I need to restrict the Write operation on the file while Read is going on, But can allow two Reads at a time. ie. two Reads can happen simultaneously, but Write can't happen at Read is going on. ... (3 Replies)
Discussion started by: satheeshalle
3 Replies

5. Shell Programming and Scripting

Mutex in Perl

Hello Everyone, I just joined this forum and this is my first post. I would like to know how can I impliment basic read/write locks in perl. I have a database (file) which can be accessed simultaneously but has to be locked while writing. If there is no such support in perl, my next... (6 Replies)
Discussion started by: superuser84
6 Replies

6. Programming

Question about read writer lock

From <<Advanced Programming in the Unix>> section 11.6, it says: Although implementations vary, readerwriter locks usually block additional readers if a lock is already held in read mode and a thread is blocked trying to acquire the lock in write mode. This prevents a constant stream of readers... (5 Replies)
Discussion started by: robin.zhu
5 Replies

7. Programming

pthread and mutex question

Hello, I have got some issue with the struct variable with passed arguments the variable in the sturct is only recognize the last value their assigned to I'm pretty confused why the mutex didn't work out here is my program: #include<stdio.h> #include<pthread.h> pthread_mutex_t lock... (3 Replies)
Discussion started by: michael23
3 Replies

8. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

9. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

10. Programming

design query: where to lock mutex for function accessing global value?

Hi, Suppose I have a function that accesses and increments a global variable . This function is run as part of thread. One locks mutex in the function and unlocks it after the processing is done. Is there any alternative way? Thanks in advance. (1 Reply)
Discussion started by: sanjayc
1 Replies
PTHREAD_MUTEX(3)					   BSD Library Functions Manual 					  PTHREAD_MUTEX(3)

NAME
pthread_mutex -- mutual exclusion primitives LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_mutex_init(pthread_mutex_t * restrict mutex, const pthread_mutexattr_t * restrict attr); int pthread_mutex_destroy(pthread_mutex_t *mutex); int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_mutex_unlock(pthread_mutex_t *mutex); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; DESCRIPTION
The pthread_mutex_init() function creates a new mutex, with attributes specified with attr. If attr is NULL, the default attributes are used. The macro PTHREAD_MUTEX_INITIALIZER can be used to initialize a mutex when the default attributes are appropriate and the mutex can be stati- cally allocated. The behavior is similar to pthread_mutex_init() with attr specified as NULL, except that no error checking is done. The pthread_mutex_destroy() function frees the resources allocated for mutex. It is possible to reinitialize a destroyed mutex, but unde- fined behavior may follow if the destroyed object is otherwise referenced. The pthread_mutex_lock() function locks mutex. If the mutex is already locked, the calling thread will block until the mutex becomes avail- able. The error conditions may vary depending on the type of the mutex; see pthread_mutexattr(3) for additional details. The pthread_mutex_trylock() function locks mutex. If the mutex is already locked, pthread_mutex_trylock() will not block waiting for the mutex, but will return an error condition. The pthread_mutex_unlock() function unlocks an acquired mutex. When operating with the default mutex type, undefined behavior follows if a thread tries to unlock a mutex that has not been locked by it, or if a thread tries to release a mutex that is already unlocked. RETURN VALUES
Upon success all described functions return zero. Otherwise, an error number will be returned to indicate the error. ERRORS
pthread_mutex_init() may fail if: [EAGAIN] The system lacks the resources to initialize another mutex. [EINVAL] The value specified by attr is invalid. [ENOMEM] The process cannot allocate enough memory to initialize another mutex. pthread_mutex_destroy() may fail if: [EBUSY] Mutex is locked by another thread. [EINVAL] The value specified by mutex is invalid. pthread_mutex_lock() may fail if: [EDEADLK] A deadlock would occur if the thread blocked waiting for mutex. [EINVAL] The value specified by mutex is invalid. pthread_mutex_trylock() may fail if: [EBUSY] Mutex is already locked. [EINVAL] The value specified by mutex is invalid. pthread_mutex_unlock() may fail if: [EINVAL] The value specified by mutex is invalid. [EPERM] The current thread does not hold a lock on mutex. SEE ALSO
pthread(3), pthread_barrier(3), pthread_cond(3), pthread_mutexattr(3), pthread_rwlock(3), pthread_spin(3) STANDARDS
These functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
July 8, 2010 BSD
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy