<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60892>60892</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
libcpp: Use pthread_cond_timedwait_relative_np for condvar waits when available
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rcombs
</td>
</tr>
</table>
<pre>
On Apple platforms, `pthread_cond_clockwait` isn't available, but `pthread_cond_timedwait_relative_np` is. This function takes the same args as `pthread_cond_timedwait`, but treats the `timespec` arg as relative to the time of the call instead of relative to the UNIX epoch.
The underlying syscall takes a relative time, so `pthread_cond_timedwait` is implemented by subtracting the passed-in value from `__gettimeofday`, so there's no particular advantage to libpthread perform that subtraction instead of doing it ourselves when relevant (and passing a relative time all the way through in cases like `wait_for` calls). This would avoid a race condition where the system time could be updated between when we internally generate an absolute time and when libpthread reads it to subtract.
`pthread_cond_timedwait_relative_np` was introduced in macOS 10.4 and iOS 2.0, so there shouldn't be any substantial version-support-conditional issues to worry about here.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMlM-O4zYMxp9GuRATeBRvMj74MO0iQC-dw-4CvQWURNvqyJIh0jHy9oXszOzsFv1zkQ2b_PjxJ0rI7PtI1KpPv6hPn3c4y5Bym20aDe9Mcrf2JcLzNAWCKaB0KY-s9K-gjtUkQyZ0F5uiu9iQ7OuCXtSxAs9R6ZMAXtEHNIFKhpnlb1niR3Il65IpoPgrXeK0Kezh6-AZujla8SmC4CsxyEDAOBJg7hmQ_1lRHau3qpIJZctVx6pE8ES2lMHcF5G34iBpjSohkLr13WII4CMLoSvffo799vtvfwBNyQ57VX1W1fO2fh0I5ugoh5uPPfCNV6GtC_yg4seVDqd_bQU8gx-nQCNFIQfmBjwbyWilyBcjEzKTe_ARrhhmgi6nsWheLj1J0Uqdw9sdC6_mMyl9YogJJszi7RwwA7orRsF-7TB4c_cEE-Wy-yADyvfiKX6E41Jx4wXSnJnClRiWgWJpl4oqKP2E0a1eS-RPIGBFNBAseAMZcpr7AXwEi0wMwb-uG7jOS5dywVKgstLNfVqWNAcHeE3eFW20BAWlX30upeFtgm4sNG4l7ZpiCObJ4YqWZCGKm_GFwEehHDGEG_QUKaMQYAQ0nMIsb8aj2xI-ACsLFxiS3nn9MCP_-zQsyMVGTm625AqREe3LF3is9vVa2r98Ab3_YWeBh9LZdhBNcbiODAtG8RjgSpl9ig88T1PK8vDOCQN45rkctgRLyvkGaNIsUFT3O9ceXHNocEft4_F0bOqDfqp3Q1vVtesac2ycqx9NbT_ZGg_WOHt8qpra2J1vdaUPldaP1eOhruu9bbqD6SrdNVXtTvVJ1RWN6MM-hOu4T7nfrT7aY_XU6F1AQ4HXe0rrSMtmUmldrq3clpwHM_es6ip4Fv6uIl4CtcEbO03q8AzfmOC_uUOX8jo8V8xQft5H-f1O2805tIPIxOrwrPRZ6XPvZZjN3qZR6XOpf388TDn9SVaUPm9olT6vXf0VAAD__-Fk7Xo">