* futex system call in write
@ 2012-06-03 5:58 Xin Tong
2012-06-03 9:16 ` Mihai Donțu
0 siblings, 1 reply; 2+ messages in thread
From: Xin Tong @ 2012-06-03 5:58 UTC (permalink / raw)
To: linux-kernel
I am a program with 2 threads, each of which calling printf in a loop.
when i strace this programs. i see besides write() gets calls a good
number of times. futex gets call many times as well. it seems to be
related to the write system call ? how is the futex system call used
here ? maybe write() is blocking and futex is used to wait the thread
up when the write finishes ? if that is the case, what about other
blocking system calls ?
[pid 9057] [ 377b4f542e] futex(0x377b78be10, FUTEX_WAIT_PRIVATE,
2, NULL <unfinished ...>
[pid 9058] [ 377b4f545f] futex(0x377b78be10, FUTEX_WAKE_PRIVATE,
1 <unfinished ...>
[pid 9057] [ 377b4f542e] <... futex resumed> ) = -1 EAGAIN
(Resource temporarily unavailable)
[pid 9058] [ 377b4f545f] <... futex resumed> ) = 0
[pid 9057] [ 377b4d8a2d] write(1, "Hello World! It's me, thread
#0!"..., 33Hello World! It's me, thread #0!
<unfinished ...>
[pid 9058] [ 377b4f542e] futex(0x377b78be10, FUTEX_WAIT_PRIVATE,
2, NULL <unfinished ...>
[pid 9057] [ 377b4d8a2d] <... write resumed> ) = 33
[pid 9057] [ 377b4f545f] futex(0x377b78be10, FUTEX_WAKE_PRIVATE,
1 <unfinished ...>
[pid 9058] [ 377b4f542e] <... futex resumed> ) = 0
[pid 9057] [ 377b4f545f] <... futex resumed> ) = 1
[pid 9058] [ 377b4d8a2d] write(1, "Hello World! It's me, thread
#1!"..., 33Hello World! It's me, thread #1!
<unfinished ...>
[pid 9057] [ 377b4f542e] futex(0x377b78be10, FUTEX_WAIT_PRIVATE,
2, NULL <unfinished ...>
[pid 9058] [ 377b4d8a2d] <... write resumed> ) = 33
[pid 9058] [ 377b4f545f] futex(0x377b78be10, FUTEX_WAKE_PRIVATE, 1) = 1
[pid 9057] [ 377b4f542e] <... futex resumed> ) = 0
[pid 9058] [ 377b4d8a2d] write(1, "Hello World! It's me, thread
#1!"..., 33Hello World! It's me, thread #1!
<unfinished ...>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: futex system call in write
2012-06-03 5:58 futex system call in write Xin Tong
@ 2012-06-03 9:16 ` Mihai Donțu
0 siblings, 0 replies; 2+ messages in thread
From: Mihai Donțu @ 2012-06-03 9:16 UTC (permalink / raw)
To: Xin Tong; +Cc: linux-kernel
On Sun, 3 Jun 2012 01:58:55 -0400 Xin Tong wrote:
> I am a program with 2 threads, each of which calling printf in a loop.
> when i strace this programs. i see besides write() gets calls a good
> number of times. futex gets call many times as well. it seems to be
> related to the write system call ? how is the futex system call used
> here ? maybe write() is blocking and futex is used to wait the thread
> up when the write finishes ? if that is the case, what about other
> blocking system calls ?
>
You should probably ask this question on a glibc mailing list.
What you're seeing is the effect of using the locking version of the
standard IO calls, where before each output a mutex is acquired to
ensure thread safety. Thus futex() has nothing to do with write(), it
is merely the underlaying system call for pthread_mutex_xxxx() calls.
--
Mihai Donțu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-06-03 9:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-03 5:58 futex system call in write Xin Tong
2012-06-03 9:16 ` Mihai Donțu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox