Questions tagged [futex]

"A futex (short for “fast userspace mutex”) is a kernel system call that programmers can use to implement basic locking, or as a building block for higher-level locking abstractions such as semaphores and POSIX mutexes or condition variables." -- From Wikipedia

https://en.wikipedia.org/wiki/Futex

107 questions
6
votes
1 answer

Futexes and blocking in the kernel

I was reading some documentation and trying out a few samples of code that issue the futex system call in Linux. I read that if a mutex is acquired by thread_a using FUTEX_LOCK_PI, and say if another thread thread_b tries to acquire the same, the…
user277465
6
votes
2 answers

Python: Process hangs with futex(0x2a5fcc0, FUTEX_WAIT_PRIVATE, 0, NULL in multithreading

So I have a Queue : q = Queue.Queue() And I'm putting some items in it. items = ["First", "Second"] for val in items: q.put(val) And I'm spawning 15 threads. for i in range(15): tname = 't-%s' % i t = my_thread(some_func, q, tname) …
user1452759
  • 8,810
  • 15
  • 42
  • 58
5
votes
0 answers

Fastest way to wake up a thread of a thread pool

I wrote a thread pool with as many threads as I have (spare cores), to avoid context switching. Whenever a new task needs to be executed, that task is added to a lock-free ring buffer for threads of the thread pool to consume. Each time a new task…
Carlo Wood
  • 5,648
  • 2
  • 35
  • 47
5
votes
2 answers

How are threads/processes parked and woken in Linux, prior to futex?

Before the futex system calls existed in Linux, what underlying system calls were used by threading libraries like pthreads to block/sleep a thread and to subsequently wake those threads from userland? For example, if a thread tries to acquire a…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
5
votes
2 answers

use futex in user space?

I need functionality of do_futex() call in user space outside of lock/unlock context. I.e., I do not need a mutex, but the exact semantics of the kernel call do_futex. It would seem it should be available in user space, since the intent was to…
n-alexander
  • 14,663
  • 12
  • 42
  • 43
4
votes
1 answer

Profiling synchronization operations in Linux

I want to profile synchronization operations, such as locking and unlocking of mutexes, semaphores etc. in Linux. I know that deep down they are implemented using futexes, so maybe it is enough to profile locking and unlocking of futexes (please…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
4
votes
2 answers

How do I find the line of C++ which locks a Linux futex?

I've got a performance problem with a large application written in C++. The program uses only 150% CPU, while the server is a 24-core hyperthreaded EPYC and other, similar applications can reliably hit the expected 4800% CPU load. iotop shows…
MSalters
  • 173,980
  • 10
  • 155
  • 350
4
votes
0 answers

app process blocked at art::ConditionVariable::WaitHoldingLocks, how to find the reason?

On Android 8.0, developed with kotlin and kotlin coroutine. All the threads will be blocked in the app. I had analyzed using strace, gdbserver to check syscall and get heap. such heap as: the first thread's heap from gdb #0 0x0000007022ab84ac in…
jie zi
  • 51
  • 1
  • 4
4
votes
1 answer

Does a futex wait/wake pair achieve acquire/release semantics?

Given this pseudocode, where there is globally an atomic int a initialized to 0: Thread 1: // ... some code here (X) ... a.store(1, relaxed); futex_wake(&a); Thread 2: if (futex_wait(&a, 1) == woken_up) { assert(a.load(relaxed) == 1); // ...…
peppe
  • 21,934
  • 4
  • 55
  • 70
4
votes
1 answer

Is test-and-set (or other atomic RMW operation) a privileged instruction on any architecture?

Hardware provides atomic instructions like test-and-set, compare-and-swap, load-linked-store-conditional. Are these privileged instructions? That is, can only the OS execute them (and thus requiring a system call)? I thought they are not privileged…
flow2k
  • 3,999
  • 40
  • 55
4
votes
1 answer

Why doesn't glib use private futexes?

When investigating some performance issues, I finally ended up in gthread-posix.c. There I found code such as: static void __attribute__((noinline)) g_mutex_lock_slowpath (GMutex *mutex) { /* Set to 2 to indicate contention. If it was zero before…
4
votes
1 answer

Measure mutex or futex latency

How could I measure a latency of mutex, semaphore or futex? I mean the latency between two events: unlock previously locked mutex and the locking that mutex. There are two cases: when all threads/processes are on the same CPU (how long will it take…
osgx
  • 90,338
  • 53
  • 357
  • 513
3
votes
2 answers

Play! framework hangs on compile, no errors reported

Just moved my app to a new CentOS server. After fiddling for a long time, I can't play to compile or get any errors. The shell output will show me the last file compiling and then hang. I'm running the Scala 0.9.1 module. I did a strace on the…
crockpotveggies
  • 12,682
  • 12
  • 70
  • 140
3
votes
2 answers

Apache mod_perl processes hang in futex_wait state

I run a fairly popular browser-based web game, running under Apache (worker) and mod_perl. During peak times, when the server is handling about 4200 requests per minute, once every 3-15 minutes or so an Apache process will hang. I have established…
parsim
  • 252
  • 2
  • 11
3
votes
2 answers

Shared pthread_cond_broadcast stuck in futex_wait

I have one "server" process a and potentially multiple "client" processes b. The server creates a shared memory file (shm_open) containing a pthread_mutex_t and a pthread_cond_t that it uses for broadcasting to the clients that something has happned…
Poohl
  • 1,932
  • 1
  • 9
  • 22