-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[libc] implement pthread condition variable support (pthread_cond_*) #85282
Comments
@llvm/issue-subscribers-libc Author: Nick Desaulniers (nickdesaulniers)
int [pthread_cond_broadcast](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_broadcast.html)(pthread_cond_t *);
int [pthread_cond_destroy](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_destroy.html)(pthread_cond_t *);
int [pthread_cond_init](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_init.html)(pthread_cond_t *, const pthread_condattr_t *);
int [pthread_cond_signal](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_signal.html)(pthread_cond_t *);
int [pthread_cond_timedwait](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_timedwait.html)(pthread_cond_t *,
pthread_mutex_t *, const struct timespec *);
int [pthread_cond_wait](https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_wait.html)(pthread_cond_t *, pthread_mutex_t *);
Specifically, FWICT libc++ depends on:
(but not pthread_cond_init??) I don't think we implement any of these. We'll likely need to implement pthread_cond_init first to begin testing the rest. |
Hi, I am new to libc, but I have experience with LLVM. |
You can absolutely try if you're interested, I will warn you it may be difficult. You can look at #85289 for a list of general things needed to add a new function. For relevant work I'd recommend looking at the pthread functions that have already been implemented in LLVM-libc, they're in https://github.com/llvm/llvm-project/tree/main/libc/src/pthread Feel free to reach out if you have more questions or want more advice on where to look. |
In particular, we seem to already have support for C11 threads. We have a |
I would like to take this if this is available, thanks! |
@elhewaty are you working on this? Or should I assign this to someone else? (These may be more difficult to implement than some of our other missing functions) |
I am sorry I will work on it, I was busy with working on this (#85592). If you think it'll be difficult for me you can suggest something that's not very hard but not trivial too. Thanks |
@nickdesaulniers just random curiosity. So currently, if a clang user tries to call these pthread_cond_* functions, it should compile, I believe. But these functions do not seem to be in libc yet, so I am curious what current implementations will be linked for those pthread_cond_* functions? |
Correct, this bug is about implementing them in llvm-libc.
If they're calling these and trying to use llvm libc then depending on what mode they're trying to use llvm-libc in, I'd expect 1 of 2 possible different failures:
|
What Nick says is correct, but also if you're just using clang and not LLVM-libc, then it will just use your system's libc. Additionally, we don't support any of the pthread functions in overlay mode due to the problems with the LLVM-libc ABI and system libc ABI possibly not matching, so in overlay mode you'll get your system libc's version. |
Looking into this a bit closer, I suspect that if we can use a similar definition for our pthread_cond_t as our cnd_t, then we can probably reuse most (all?) of libc/src/threads/linux/CndVar.h. Looking at libc/test/integration/src/threads/cnd_test.cpp, it looks like to start testing any of these, we'll need I'm going to take this; @elhewaty I'm going to refer you to some of our perhaps easier beginner bugs: https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+label%3Alibc+label%3A%22good+first+issue%22 |
It might also be useful to add support for |
Basic support for pthread condition variables. Does not support: - pthread_cond_{timedwait|broadcast} - non-nullptr pthread_condattr_t values for pthread_cond_init Relies on the existing CndVar, which should be moved from libc/src/threads/linux/CndVar.h to libc/src/__support/threads/. Link: llvm#85282 Link: llvm#88580 Link: llvm#88581 Link: llvm#88582
int pthread_cond_broadcast(pthread_cond_t *);
int pthread_cond_destroy(pthread_cond_t *);
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
int pthread_cond_signal(pthread_cond_t *);
int pthread_cond_timedwait(pthread_cond_t *,
pthread_mutex_t *, const struct timespec *);
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
Specifically, FWICT libc++ depends on:
(but not pthread_cond_init?? PTHREAD_COND_INITIALIZER is used instead) I don't think we implement any of these. We'll likely need to implement pthread_cond_init first to begin testing the rest.
The text was updated successfully, but these errors were encountered: