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

Issues with Thread Waiting on Mac OS #1472

Open
JerryHyun opened this issue Mar 18, 2024 · 6 comments
Open

Issues with Thread Waiting on Mac OS #1472

JerryHyun opened this issue Mar 18, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@JerryHyun
Copy link
Contributor

JerryHyun commented Mar 18, 2024

Problem Description

When testing the eCAL library on mac OS, I noticed that sometimes it will execute the pthread_cond_timedwait_relative_np() function and get stuck for a very long time (I don't know the exact reason).

"ecal/ecal/core/src/io/mtx/linux/ecal_named_mutex_impl.cpp"
"ecal/ecal/core/src/ecal_event.cpp"

#ifndef ECAL_OS_MACOS
          ret = pthread_cond_timedwait(&mtx_->cvar, &mtx_->mtx, ts_);
#else
          ret = pthread_cond_timedwait_relative_np(&mtx_->cvar, &mtx_->mtx, ts_);
#endif

Looking at the source code above, eCAL on mac os uses the pthread_cond_timedwait_relative_np() function.
Why are you using pthread_cond_timedwait_relative_np() and not the pthread_cond_timedwait() function? (I have confirmed that the pthread_cond_timedwait() function exists on mac OS as well).

How to reproduce

I'm not sure how to reproduce it.

How did you get eCAL?

Custom Build / Built from source

Environment

  • eCAL: v 5.12.1
  • OS : mac os v 14.1.2

eCAL System Information

No response

@JerryHyun JerryHyun changed the title Issues with Thread Waiting on Mac OS / Thread Waiting on Mac OS Issues with Thread Waiting on Mac OS Mar 18, 2024
@KerstinKeller
Copy link
Contributor

@hannemn do you remember?
I tried to track down the original commit that first added MacOS, but that was from a time where we synched two repos, and I was unable to pin it down. Most likely related to monotonic clocks or similar.
Does it work reliably, if changed to pthread_cond_timedwait ?

@JerryHyun
Copy link
Contributor Author

JerryHyun commented Mar 19, 2024

I haven't tried replacing it with pthread_cond_timedwait yet.
I'll try to change it and test it.

@hannemn
Copy link
Contributor

hannemn commented Mar 20, 2024

Hi @JerryHyun, thanks for the finding! I just had a quick look into the implementation of pthread_cond_timedwait_relative_np and seems to be case that we utilize the function in the wrong manner. Even though Apple declared the time parameter in the function signature as const struct timespec *abstime which suggested the argument is interpreted as absolute timepoint, it has to be actually a relative timespan according to the implementation. I will try to fix this in a generic manner to keep code section further on platform independent and will keep you posted once I have a first bugfix available.

@hannemn hannemn self-assigned this Mar 20, 2024
@hannemn hannemn added the bug Something isn't working label Mar 20, 2024
@hannemn
Copy link
Contributor

hannemn commented Mar 27, 2024

Can you please crosscheck with this branch https://github.com/eclipse-ecal/ecal/tree/hotfix/timedwait-relative-mac-5-12 (it's based on 5.12.x) if the blocking issue at pthread_cond_timedwait_relative_np still appears on your mac? I have unfortunately no mac hardware here available to test my code changes.

@JerryHyun
Copy link
Contributor Author

Hi @hannemn
Yes, I see.
I'll test it and let you know if there are any issues.

@KerstinKeller
Copy link
Contributor

@JerryHyun can you provide feedback on this issue? does the hotfix solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants