0

Suppose, if we have a choice to make between wait_until and select(timveval), then which one is better? Do anyone has performance benefit over the other or is it implementation defined?


Why this question?
Was trying to solve this problem: Android: C++ thread not waking up if screen-locked or in background. Works fine when app is in use
To summarise, a thread containing std::condition_variable::wait_until is Not waking up when an Android device is locked. This is happening probably due to CPU going for sleep. If I replace it with socket > select > timeval (wait), as mentioned in select man page, then the situation is little better, where the thread wakes up "sometimes". As of now, none of them solve the problem.

Community
  • 1
  • 1
iammilind
  • 68,093
  • 33
  • 169
  • 336
  • Did you try [poll(2)](http://man7.org/linux/man-pages/man2/poll.2.html) which might be marginally better than `select` ? See also [time(7)](http://man7.org/linux/man-pages/man7/time.7.html) – Basile Starynkevitch Dec 07 '16 at 05:58
  • @BasileStarynkevitch, No I haven't tried `poll()` before. Do you have any reference on it; i.e. in what situations will it be better than `select()`? For now I have to deal with only 1 or 2 sockets at a time. What is the link to `time(7)` regarding, is it another alternative? – iammilind Dec 07 '16 at 06:05
  • Perhaps consider some `timerfd_create` to be used in conjunction with `poll` (which is probably slightly faster than `select`, notably when you have many file descriptors, or one with some large number). But YMMV and you need to benchmark. – Basile Starynkevitch Dec 07 '16 at 06:10
  • 1
    @BasileStarynkevitch Using `poll` instead of select would have no major advantage in his case, since he is dealing with just 2 sockets. – Arunmu Dec 07 '16 at 06:12
  • I would prefer `wait_until` over `select` if I have to block my thread because, use of `condition_variable` in the code looks more contextually applicable. – Arunmu Dec 07 '16 at 06:15

0 Answers0