Sponsored Content
Top Forums Programming Can Mutex be replaced with anything? Post 302383182 by Corona688 on Monday 28th of December 2009 05:44:01 PM
Old 12-28-2009
Quote:
Originally Posted by fpmurphy
Interlocked variables/operations are mostly a Microsoft win32 thing. Because some architectures capable of running Linux do not have the necessary hardware support, interlocked variables/operations are not available in Linux user space. They are available only in the kernel and only on some architectures.
If I'm reading it right, an interlocked variable looks a lot like a linux futex, the atomic part of which does happen in userspace.
 

10 More Discussions You Might Find Interesting

1. Programming

Threads and Mutex

Hi all, I am working in a UNIX/C environment. I would like to understand more about MUTEX and Threads. Can someone explain me these concepts and how they are related. Vijay (2 Replies)
Discussion started by: vthasan
2 Replies

2. UNIX for Dummies Questions & Answers

mutex

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

3. Shell Programming and Scripting

mutex in shell programing

A shell in crontab per 5 min write a file B shell in crontab per 6 min read a file how to lock the share file a ;avioid confilict in write and read? Thx : -) (1 Reply)
Discussion started by: zz_xm
1 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. Programming

difference between Mutex and semaphores

Hi, can someone explain me the difference between mutex and semaphores? Thanks (1 Reply)
Discussion started by: rvan
1 Replies

6. UNIX for Dummies Questions & Answers

what is diff b/w semaphore and mutex

can u tell me what is the exact difference b/w mutex and semaphore and what is the diff b/w counting semaphore and binary semaphore amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

7. 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

8. Programming

Mutex will not work

I am trying to use mutex in my multi-tread project, but they don't seem to work. I have created a simple demonstration of the problem. This is NOT how I would use a mutex, only a demonstration of the problem: #include <stdio.h> #include <pthread.h> int main() { int val; ... (3 Replies)
Discussion started by: ChrisWilliams
3 Replies

9. Programming

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... (2 Replies)
Discussion started by: cjjoy
2 Replies

10. 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
FUTEX(7)						     Linux Programmer's Manual							  FUTEX(7)

NAME
futex - fast user-space locking SYNOPSIS
#include <linux/futex.h> DESCRIPTION
The Linux kernel provides futexes ("Fast user-space mutexes") as a building block for fast user-space locking and semaphores. Futexes are very basic and lend themselves well for building higher level locking abstractions such as POSIX mutexes. This page does not set out to document all design decisions but restricts itself to issues relevant for application and library develop- ment. Most programmers will in fact not be using futexes directly but instead rely on system libraries built on them, such as the NPTL pthreads implementation. A futex is identified by a piece of memory which can be shared between different processes. In these different processes, it need not have identical addresses. In its bare form, a futex has semaphore semantics; it is a counter that can be incremented and decremented atomi- cally; processes can wait for the value to become positive. Futex operation is entirely user space for the noncontended case. The kernel is involved only to arbitrate the contended case. As any sane design will strive for noncontention, futexes are also optimized for this situation. In its bare form, a futex is an aligned integer which is touched only by atomic assembler instructions. Processes can share this integer using mmap(2), via shared memory segments or because they share memory space, in which case the application is commonly called multi- threaded. Semantics Any futex operation starts in user space, but it may be necessary to communicate with the kernel using the futex(2) system call. To "up" a futex, execute the proper assembler instructions that will cause the host CPU to atomically increment the integer. Afterward, check if it has in fact changed from 0 to 1, in which case there were no waiters and the operation is done. This is the noncontended case which is fast and should be common. In the contended case, the atomic increment changed the counter from -1 (or some other negative number). If this is detected, there are waiters. User space should now set the counter to 1 and instruct the kernel to wake up any waiters using the FUTEX_WAKE operation. Waiting on a futex, to "down" it, is the reverse operation. Atomically decrement the counter and check if it changed to 0, in which case the operation is done and the futex was uncontended. In all other circumstances, the process should set the counter to -1 and request that the kernel wait for another process to up the futex. This is done using the FUTEX_WAIT operation. The futex(2) system call can optionally be passed a timeout specifying how long the kernel should wait for the futex to be upped. In this case, semantics are more complex and the programmer is referred to futex(2) for more details. The same holds for asynchronous futex wait- ing. VERSIONS
Initial futex support was merged in Linux 2.5.7 but with different semantics from those described above. Current semantics are available from Linux 2.5.40 onward. NOTES
To reiterate, bare futexes are not intended as an easy to use abstraction for end-users. Implementors are expected to be assembly literate and to have read the sources of the futex user-space library referenced below. This man page illustrates the most common use of the futex(2) primitives: it is by no means the only one. SEE ALSO
futex(2) Fuss, Futexes and Furwocks: Fast Userlevel Locking in Linux (proceedings of the Ottawa Linux Symposium 2002), futex example library, futex-*.tar.bz2 <ftp://ftp.kernel.org/pub/linux/kernel/people/rusty/>. COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-08-05 FUTEX(7)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy