Skip to contentSkip to conversation

epoll(7) redux

DISCUSSION Sam Varshavchik 3 participants 6 messages Apr 9, 2008 – May 21, 2008 4 messages not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Q2

Can two epoll sets wait for the same file descriptor? If so, are events
reported to both epoll file descriptors?

A2

Yes, and events would be reported to both. However, it is not
recommended.

=========

It's not clear what "not recommended" means. Furthermore, I don't think there's anything wrong with two epoll file descriptors waiting for different events on the same file descriptor. One's waiting for POLLIN, the other for POLLOUT. What's wrong with that?

#2 lore raw
In reply to a message not in the archive
Quoted 7 lines · Sam Varshavchik

Q2

Can two epoll sets wait for the same file descriptor? If so, are events
reported to both epoll file descriptors?

A2

Quoted 8 lines

Yes, and events would be reported to both. However, it is not recommended.

=========

It's not clear what "not recommended" means. Furthermore, I don't think there's anything wrong with two epoll file descriptors waiting for different events on the same file descriptor. One's waiting for POLLIN, the other for POLLOUT. What's wrong with that?

Perhaps Davide has some thought to offer here?

Signature · 9 lines
Michael Kerrisk
Maintainer of the Linux man-pages project
http://www.kernel.org/doc/man-pages/
Want to report a man-pages bug? Look here:
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
In reply to a message not in the archive
Quoted 10 lines · Michael Kerrisk
Quoted 9 lines · Sam Varshavchik

Q2

Can two epoll sets wait for the same file descriptor? If so, are events
reported to both epoll file descriptors?

A2

Yes, and events would be reported to both. However, it is not recommended.

Quoted 8 lines
Quoted 6 lines

=========

It's not clear what "not recommended" means. Furthermore, I don't think there's anything wrong with two epoll file descriptors waiting for different events on the same file descriptor. One's waiting for POLLIN, the other for POLLOUT. What's wrong with that?

Perhaps Davide has some thought to offer here?

You can do it. No problem as far as epoll goes. The "recommended" bit was more because it is very easy to get things wrong from an application perspective POV, when doing that.
In the case above, first POLLOUT is "almost" always signaled, so you'll receive continuous events over there. Second, if both events shows up at the same time (say in two different threads) and you do not take care of it, you'll end up handling the same fd, at the same time, in two different threads.
*Many* users got this wrong, so *many* times, that the "not recommended" is the least warning we can issue.

- Davide

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 19 lines · Davide Libenzi
Quoted 17 lines · Michael Kerrisk
Quoted 15 lines · Sam Varshavchik

Q2

Can two epoll sets wait for the same file descriptor? If so, are events
reported to both epoll file descriptors?

A2

Yes, and events would be reported to both. However, it is not recommended.

=========

It's not clear what "not recommended" means. Furthermore, I don't think there's anything wrong with two epoll file descriptors waiting for different events on the same file descriptor. One's waiting for POLLIN, the other for POLLOUT. What's wrong with that?

Quoted 4 lines
Quoted 1 line

Perhaps Davide has some thought to offer here?

You can do it. No problem as far as epoll goes. The "recommended" bit was more because it is very easy to get things wrong from an application perspective POV, when doing that.
In the case above, first POLLOUT is "almost" always signaled, so you'll receive continuous events over there. Second, if both events shows up at the same time (say in two different threads) and you do not take care of it, you'll end up handling the same fd, at the same time, in two different threads.

That's what I had in mind. One thread has the fd in its epoll fd for POLLIN, and handles the read aspect of it. Another thread puts the fd into a different epoll fd, for POLLOUT, and handles the writing aspect of it. It shouldn't be too difficult for both threads to correctly implement their corresponding semantics.

#7 lore raw
In reply to a message not in the archive
Quoted 38 lines · Sam Varshavchik
Quoted 27 lines · Davide Libenzi
Quoted 16 lines · Michael Kerrisk
Quoted 3 lines · Sam Varshavchik

Q2

Can two epoll sets wait for the same file descriptor? If so, are

events

Quoted 5 lines

reported to both epoll file descriptors?

A2

Yes, and events would be reported to both. However, it is not

recommended.

Quoted 4 lines

=========

It's not clear what "not recommended" means. Furthermore, I don't

Quoted 8 lines

think

Quoted 1 line

there's anything wrong with two epoll file descriptors waiting for

different

Quoted 1 line

events on the same file descriptor. One's waiting for POLLIN, the

other for

Quoted 1 line

POLLOUT. What's wrong with that?

Perhaps Davide has some thought to offer here?

Quoted 8 lines

You can do it. No problem as far as epoll goes. The "recommended" bit was more because it is very easy to get things wrong from an application perspective POV, when doing that.
In the case above, first POLLOUT is "almost" always signaled, so you'll receive continuous events over there. Second, if both events shows up at the same time (say in two different threads) and you do not take care of it, you'll end up handling the same fd, at the same time, in two different threads.

Quoted 5 lines

That's what I had in mind. One thread has the fd in its epoll fd for POLLIN, and handles the read aspect of it. Another thread puts the fd into a different epoll fd, for POLLOUT, and handles the writing aspect of it. It shouldn't be too difficult for both threads to correctly implement their corresponding semantics.

So how about I change:

A2. Yes, and events would be reported to both. However, it is not recommended.

to:

Yes, and events would be reported to both. However, careful programming may be needed to do this correctly.

?

Cheers,

Michael

Signature · 8 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw
In reply to a message not in the archive
Quoted 53 lines · Michael Kerrisk
Quoted 38 lines · Sam Varshavchik
Quoted 27 lines · Davide Libenzi
Quoted 16 lines · Michael Kerrisk
Quoted 3 lines · Sam Varshavchik

Q2

Can two epoll sets wait for the same file descriptor? If so, are

events

Quoted 5 lines

reported to both epoll file descriptors?

A2

Yes, and events would be reported to both. However, it is not

recommended.

Quoted 4 lines

=========

It's not clear what "not recommended" means. Furthermore, I don't

Quoted 8 lines

think

Quoted 1 line

there's anything wrong with two epoll file descriptors waiting for

different

Quoted 1 line

events on the same file descriptor. One's waiting for POLLIN, the

other for

Quoted 1 line

POLLOUT. What's wrong with that?

Perhaps Davide has some thought to offer here?

Quoted 8 lines

You can do it. No problem as far as epoll goes. The "recommended" bit was more because it is very easy to get things wrong from an application perspective POV, when doing that.
In the case above, first POLLOUT is "almost" always signaled, so you'll receive continuous events over there. Second, if both events shows up at the same time (say in two different threads) and you do not take care of it, you'll end up handling the same fd, at the same time, in two different threads.

Quoted 5 lines

That's what I had in mind. One thread has the fd in its epoll fd for POLLIN, and handles the read aspect of it. Another thread puts the fd into a different epoll fd, for POLLOUT, and handles the writing aspect of it. It shouldn't be too difficult for both threads to correctly implement their corresponding semantics.

So how about I change:

A2. Yes, and events would be reported to both. However, it is not recommended.

Quoted 6 lines

to:

Yes, and events would be reported to both. However, careful programming may be needed to do this correctly.

?

Looks OK to me.

- Davide

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html