Sponsored Content
Top Forums Programming locking mutexes, threads & semahores Post 302270383 by Sivaswami on Sunday 21st of December 2008 04:57:24 PM
Old 12-21-2008
1) mutex_lock works for solaris thread where as pthread_mutex_lock works between pthreads
 

9 More Discussions You Might Find Interesting

1. Programming

C++ variable scope and mutexes

I've been wondering if I can make mutexes much easier to use in C++ with creative use of a locking class and variable scope, but I'm not sure if things happen in the order I want. Here's pseudocode for something that could use the class: int someclass::getvalue() { int retval; ... (0 Replies)
Discussion started by: Corona688
0 Replies

2. Programming

How to wait on multiple semaphores/mutexes

I thought one used the select function to wait on multiple semaphores but according to http://opengroup.org/onlinepubs/007908799/xsh/select.html, the select function is only good for I/O features (like pipes and fifos). How can I block for multiple semaphores? What if I have a mixture of things... (1 Reply)
Discussion started by: siegfried
1 Replies

3. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

4. UNIX for Dummies Questions & Answers

pthread condition variables and mutexes?

I am trying to understand the exact difference between condition variables and mutexes in thread synchronization ?. I know mutex will control the thread access to shared data and condition variables will be useful for waiting for certain event or condition to occur . But I couldn't understand why... (2 Replies)
Discussion started by: siddaonline
2 Replies

5. UNIX for Advanced & Expert Users

Native & Green Threads

Hi, While compiling an application on Solaris 10, I observe the following printout. The same compilation passed some time ago(but perhaps the compilers were different then! We are maintaining this product and lost track of previous changes). ... (1 Reply)
Discussion started by: smanu
1 Replies

6. Shell Programming and Scripting

File locking (Unix/Linux) & sftp

Hi all, Can anyone help ...on how to ensure that a file is locked . thanks & regards, Soodoo ---------------------------------------- Problem description: - We usually use the mv command in scripts to make sure that a file is complete and not being written to by another process. ... (1 Reply)
Discussion started by: soodoo
1 Replies

7. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. UNIX for Advanced & Expert Users

mandatory & record locking using client server architecture

Hi I want a program of employee database locking with mendatory & record locking using client server architecture .there are two type of clients one which has all permissions of read/write called supervisor & another can only read the file.employee data base should contain 1) name 2)ID 3)BU... (1 Reply)
Discussion started by: rluha
1 Replies

9. HP-UX

Spawn more than 8 threads OpenMP & HPUX

Hi folks, I am trying to run more than 8 threads in OpenMP team on my HP-UX 11i v3 system (without root access), but NO success. Compiler: aCC A.06.26 I tried to setup: OMP_NUM_THREADS, omp_set_num_threads(), max_thread_proc=1000, nkthread=8416, set_dynamic=0 Machine has 2 processors... (1 Reply)
Discussion started by: ATveretinov
1 Replies
mutex(5)						Standards, Environments, and Macros						  mutex(5)

NAME
mutex - concepts relating to mutual exclusion locks DESCRIPTION
Mutual exclusion locks (mutexes) prevent multiple threads from simultaneously executing critical sections of code which access shared data (that is, mutexes are used to serialize the execution of threads). All mutexes must be global. A successful call to acquire a mutex will cause another thread that is also trying to lock the same mutex to block until the owner thread unlocks the mutex. Mutexes can synchronize threads within the same process or in other processes. Mutexes can be used to synchronize threads between processes if the mutexes are allocated in writable memory and shared among the cooperating processes (see mmap(2)), and have been initialized for this task. The following table lists mutex functions and the actions they perform. +-----------------------+-----------------------------------+ | FUNCTION | ACTION | |mutex_init | Initialize a mutex. | |mutex_destroy | Destroy a mutex. | |mutex_lock | Lock a mutex. | |mutex_trylock | Attempt to lock a mutex. | |mutex_unlock | Unlock a mutex. | |pthread_mutex_init | Initialize a mutex. | |pthread_mutex_destroy | Destroy a mutex. | |pthread_mutex_lock | Lock a mutex. | |pthread_mutex_trylock | Attempt to lock a mutex. | |pthread_mutex_unlock | Unlock a mutex. | +-----------------------+-----------------------------------+ Initialization Mutexes are either intra-process or inter-process, depending upon the argument passed implicitly or explicitly to the initialization of that mutex. A statically allocated mutex does not need to be explicitly initialized; by default, a statically allocated mutex is initial- ized with all zeros and its scope is set to be within the calling process. For inter-process synchronization, a mutex needs to be allocated in memory shared between these processes. Since the memory for such a mutex must be allocated dynamically, the mutex needs to be explicitly initialized with the appropriate attribute that indicates inter- process use. Locking and Unlocking A critical section of code is enclosed by a call to lock the mutex and the call to unlock the mutex to protect it from simultaneous access by multiple threads. Only one thread at a time may possess mutually exclusive access to the critical section of code that is enclosed by the mutex-locking call and the mutex-unlocking call, whether the mutex's scope is intra-process or inter-process. A thread calling to lock the mutex either gets exclusive access to the code starting from the successful locking until its call to unlock the mutex, or it waits until the mutex is unlocked by the thread that locked it. Mutexes have ownership, unlike semaphores. Only the thread that locked a mutex, (that is, the owner of the mutex), should unlock it. If a thread waiting for a mutex receives a signal, upon return from the signal handler, the thread resumes waiting for the mutex as if there was no interrupt. Caveats Mutexes are almost like data - they can be embedded in data structures, files, dynamic or static memory, and so forth. Hence, they are easy to introduce into a program. However, too many mutexes can degrade performance and scalability of the application. Because too few mutexes can hinder the concurrency of the application, they should be introduced with care. Also, incorrect usage (such as recursive calls, or violation of locking order, and so forth) can lead to deadlocks, or worse, data inconsistencies. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mmap(2), shmop(2), mutex_destroy(3C), mutex_init(3C), mutex_lock(3C), mutex_trylock(3C), mutex_unlock(3C), pthread_create(3C), pthread_mutex_destroy(3C), pthread_mutex_init(3C), pthread_mutex_lock(3C), pthread_mutex_trylock(3C), pthread_mutex_unlock(3C), pthread_mutexattr_init(3C), attributes(5), standards(5) NOTES
In the current implementation of threads, pthread_mutex_lock(), pthread_mutex_unlock(), mutex_lock() mutex_unlock(), pthread_mutex_try- lock(), and mutex_trylock() do not validate the mutex type. Therefore, an uninitialized mutex or a mutex with an invalid type does not return EINVAL. Interfaces for mutexes with an invalid type have unspecified behavior. By default, if multiple threads are waiting for a mutex, the order of acquisition is undefined. USYNC_THREAD does not support multiple mappings to the same logical synch object. If you need to mmap() a synch object to different loca- tions within the same address space, then the synch object should be initialized as a shared object USYNC_PROCESS for Solaris, and PTHREAD_PROCESS_PRIVATE for POSIX. SunOS 5.10 20 Jul 1998 mutex(5)
All times are GMT -4. The time now is 08:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy