Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: pthread condvar timeouts are broken #2967

Merged
merged 2 commits into from
Mar 5, 2018

Conversation

lunixbochs
Copy link
Contributor

@lunixbochs lunixbochs commented Mar 5, 2018

Problem: pthread condvar timeouts are broken

Solution:

  • Use pthread_cond_timedwait_relative_np() on macOS
  • Use pthread_cond_timedwait_monotonic_np() on old versions of Android
  • Use pthread_condattr_setclock(CLOCK_MONOTONIC) on other platforms

Context: zeromq/czmq#1873 (comment)

@@ -183,7 +183,7 @@ class condition_variable_t
{
pthread_condattr_t attr;
pthread_condattr_init (&attr);
#ifndef ZMQ_HAVE_OSX
#if !defined(ZMQ_HAVE_OSX) || (defined(ZMQ_HAVE_ANDROID) && !defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still failing the android build job. Maybe the condition is missing some brackets?

@bluca
Copy link
Member

bluca commented Mar 5, 2018

A build failure is introduced in the Android build, could you please fix it?

In file included from src/mailbox_safe.hpp:43:0,
                 from src/mailbox_safe.cpp:31:
src/condition_variable.hpp: In constructor 'zmq::condition_variable_t::condition_variable_t()':
src/condition_variable.hpp:189:58: error: 'pthread_condattr_setclock' was not declared in this scope
         pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);

@@ -212,8 +219,16 @@ class condition_variable_t
timeout.tv_sec++;
timeout.tv_nsec -= 1000000000;
}

#ifdef ZMQ_HAVE_OSX
rc = pthread_cond_timedwait_relative_np (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this available on all versions of OSX? There have been many issues with OSX and clocks over the years, see:
#2537
#2538
#1351
#1354

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found pthread_cond_timedwait_relative_np recommended at least 6 years ago for macOS.

For Android, looks like that was the wrong check, and I should just be checking for r21 or not:
https://stackoverflow.com/questions/44580542/ndk-builder-r15-finds-neither-have-pthread-cond-timedwait-monotonic-nor-pthread

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's referenced in https://opensource.apple.com/source/Libc/Libc-166/pthreads.subproj/pthread_cond.c, which is literally OS X 10.0. So yeah I'd say it's probably fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android build fixed. The clang format build is still erroring, but not on my changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for your contribution, merged

@bluca bluca merged commit 3658b2b into zeromq:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants