futex

Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+

帅比萌擦擦* 提交于 2020-01-15 07:50:28
问题 I am investigating Intel CPU atomic features on my Haswell CPU (a 4/8 core 2.3-3.9ghz i7-4790M), and am finding it really hard to construct eg. reliable mutex_lock() and mutex_unlock() operations as suggested by for instance the GCC manual: 6.53 x86-Specific Memory Model Extensions for Transactional Memory The x86 architecture supports additional memory ordering flags to mark lock critical sections for hardware lock elision. These must be specified in addition to an existing memory model to

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

☆樱花仙子☆ 提交于 2020-01-10 03:20:11
问题 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 mutex, the userland implementation will block the thread (perhaps after a short spinning interval), but I can't find the syscalls that are used for this (other than futex which are a relatively recent creation). 回答1: Before futex and current

Is there a way to call library thread-local init/cleanup on thread creation/destruction?

牧云@^-^@ 提交于 2020-01-04 07:45:10
问题 This question is similar to How to call a function on a thread's creation and exit? but more specific. In another multi-process shared memory project I used a combination of an __attribute__((constructor)) labeled library init routine, lazy initialisation for each thread, and robust futexes to make sure resources weren't leaked in the shared memory even if a sys admin chose to SIGKILL one of the processes using it. However futexes within the APIs are way too heavyweight for my current project

Futex based locking mechanism

落爺英雄遲暮 提交于 2019-12-21 21:14:12
问题 Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS) 回答1: Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level,

Java periodically hangs at futex and very low IO output

馋奶兔 提交于 2019-12-21 07:36:47
问题 Currently my application periodically blocked in IO , and the output is very low . I use some command to trace the process. By using jstack i found that the app is hanging at FileOutputStream.writeBytes. By using strace -f -c -p pid to collect syscall info, i found that. For normal situation, it has both futex and write syscalls. But when it went unnormal, there are only futex syscalls. The app keeps calling futex but all failed and throw ETIMEDOUT, just like this: <futex resumed> =-1

Linux futex for 64-bits

自古美人都是妖i 提交于 2019-12-13 02:25:10
问题 I am on a 64-bit Linux box: Linux illin793 2.6.32-279.5.2.el6.x86_64 #1 SMP Tue Aug 14 11:36:39 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux From man futex: int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3); So, here futex works with 32-bits value. Is there futex on Linux that works with 64-bits value? 回答1: There is currently no support for 64-bit futexes on Linux. There have been patches to add support circulating from as far back as 2007, but I have no

How to debug a futex contention shown in strace?

你说的曾经没有我的故事 提交于 2019-12-09 10:36:09
问题 I'm debugging an issue in a multi-threaded linux process, where a certain thread appears to not execute for few seconds. Looking at strace output revealed it waits for futex e.g. 1673109 14:36:28.600329 futex(0x44b8d20, FUTEX_WAIT_PRIVATE, 1673109 14:36:33.221850 <... futex resumed> ) = 0 <4.621514> How can I find out out what this futex(0x44b8d20) refers to in user space, i.e. how to map this to a locking construct which is using futex internally. 回答1: I would use a simple systemtap script

Futex based locking mechanism

假装没事ソ 提交于 2019-12-04 17:41:07
Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS) Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level, language-specific API (which will almost certainly use pthreads itself). Have a look at https://github.com/avsm

Java periodically hangs at futex and very low IO output

我与影子孤独终老i 提交于 2019-12-04 01:34:58
Currently my application periodically blocked in IO , and the output is very low . I use some command to trace the process. By using jstack i found that the app is hanging at FileOutputStream.writeBytes. By using strace -f -c -p pid to collect syscall info, i found that. For normal situation, it has both futex and write syscalls. But when it went unnormal, there are only futex syscalls. The app keeps calling futex but all failed and throw ETIMEDOUT, just like this: <futex resumed> =-1 ETIMEDOUT (Connecton timed out) futex(Ox7f823, FUTEX_WAKE_PRIVATE,1)=0 futex(Ox7f824, FUTEX_WAIT_BITSET

How to debug a futex contention shown in strace?

冷暖自知 提交于 2019-12-03 12:46:45
I'm debugging an issue in a multi-threaded linux process, where a certain thread appears to not execute for few seconds. Looking at strace output revealed it waits for futex e.g. 1673109 14:36:28.600329 futex(0x44b8d20, FUTEX_WAIT_PRIVATE, 1673109 14:36:33.221850 <... futex resumed> ) = 0 <4.621514> How can I find out out what this futex(0x44b8d20) refers to in user space, i.e. how to map this to a locking construct which is using futex internally. Akin Ocal I would use a simple systemtap script so that would help you to quickly find out addresses of contended futex locks. When I say address,