OpenBSD CVS

CVS log for src/lib/librthread/synch.h


[BACK] Up to [local] / src / lib / librthread

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.10 / (download) - annotate - [select for diffs], Sun Jan 7 19:44:28 2024 UTC (5 months ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, HEAD
Changes since 1.9: +5 -9 lines
Diff to previous 1.9 (colored)

libc, librthread: _twait: subtraction is not comparison

Compare the current time with the absolute timeout before computing
the relative timeout to avoid arithmetic overflow.  Fixes a bug where
large negative absolute timeouts are subtracted into large positive
relative timeouts and incorrectly cause the caller to block.

While here, use timespeccmp(3) and timespecsub(3) to simplify the
code.

Thread: https://marc.info/?l=openbsd-tech&m=169945962503129&w=2

Revision 1.9 / (download) - annotate - [select for diffs], Wed Nov 8 15:51:28 2023 UTC (7 months ago) by cheloha
Branch: MAIN
Changes since 1.8: +2 -2 lines
Diff to previous 1.8 (colored)

libc, librthread: _twait: fully validate absolute timeout

Use timespecisvalid(3) to check both bounds for tv_nsec.

Link: https://marc.info/?l=openbsd-tech&m=169913314230496&w=2

ok miod@

Revision 1.8 / (download) - annotate - [select for diffs], Sun Jun 13 21:11:54 2021 UTC (2 years, 11 months ago) by kettenis
Branch: MAIN
CVS Tags: OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0
Changes since 1.7: +8 -10 lines
Diff to previous 1.7 (colored)

Save and restore errno around FUTEX_WAIT futex(2) operations.  While there
remove the unused _wait() function in librthread such that we don't have to
add the save/restore sequence there.

Fixed building Python as a race with another thread unlocking a futex(2)
would make futex(2) set errno to EAGAIN which would confuse Python in
beleiving that readdir(2) failed instead of reaching the end of the
directory.

Spotted and tested by tb@
ok bluhm@

Revision 1.7 / (download) - annotate - [select for diffs], Fri May 21 16:52:42 2021 UTC (3 years ago) by kettenis
Branch: MAIN
Changes since 1.6: +14 -6 lines
Diff to previous 1.6 (colored)

The implementation of the FUTEX_WAIT option in futex(2) is subtly broken.
Unfortunately libc and libpthread rely on the broken behaviour.  Adjust
the code in those libraries such that it works with both the old and the
proposed new behaviour.  The kernel changes that fix the issue will be
committed in a week or so to give those who do their own builds a chance
to update these libraries before we make the change.

ok mpi@, deraadt@

Revision 1.6 / (download) - annotate - [select for diffs], Thu Oct 24 12:32:18 2019 UTC (4 years, 7 months ago) by sthen
Branch: MAIN
CVS Tags: OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7
Changes since 1.5: +11 -4 lines
Diff to previous 1.5 (colored)

Backout previous synch.h commit (r1.5, "Use process-private futexes to avoid
the uvm_map lookup overhead"). This causes hangs with Python, seen easily
by trying to build ports/graphics/py-Pillow.

Revision 1.5 / (download) - annotate - [select for diffs], Mon Oct 21 10:06:31 2019 UTC (4 years, 7 months ago) by mpi
Branch: MAIN
Changes since 1.4: +5 -12 lines
Diff to previous 1.4 (colored)

Use process-private futexes to avoid the uvm_map lookup overhead.

While here kill unused _wait() function.

ok visa@

Revision 1.4 / (download) - annotate - [select for diffs], Fri Jun 8 13:53:01 2018 UTC (6 years ago) by pirofti
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6, OPENBSD_6_5_BASE, OPENBSD_6_5, OPENBSD_6_4_BASE, OPENBSD_6_4
Changes since 1.3: +1 -3 lines
Diff to previous 1.3 (colored)

New semaphore implementation making sem_post async-safe.

POSIX dictates that sem_post() needs to be async-safe here[0] and is
thus included in the list of safe functions to call from within a signal
handler here[1].

The old semaphore implementation is using spinlocks and __thrsleep to
synchronize between threads.

Let's say there are two threads: T0 and T1 and the semaphore has V=0.
T1 calls sem_wait() and it will now sleep (spinlock) until someone else
sem_post()'s. Let's say T0 sends a signal to T1 and exits.
The signal handler calls sem_post() which is meant to unblock T1 by
incrementing V. With the old semaphore implementation we we are now in a
deadlock as sem_post spinlocks on the same lock.

The new implementation does not suffer from this defect as it
uses futexes to resolve locking and thus sem_post does not need to spin.
Besides fixing this defect and making us POSIX compliant, this should
also improve performance as there should be less context switching and
thus less time spent in the kernel.

For architectures that do not provied futexes and atomic operations,
the old implementation will be used and it is now being renamed to
rthread_sem_compat as discussed with mpi@.

[0] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html
[1] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html

OK visa@, mpi@, guenther@

Revision 1.3, Tue Sep 5 02:40:54 2017 UTC (6 years, 9 months ago) by guenther
Branch: MAIN
Changes since 1.2: +1 -1 lines
FILE REMOVED

Move mutex, condvar, and thread-specific data routes, pthread_once, and
pthread_exit from libpthread to libc, along with low-level bits to
support them.  Major bump to both libc and libpthread.

Requested by libressl team.  Ports testing by naddy@
ok kettenis@

Revision 1.2 / (download) - annotate - [select for diffs], Mon May 29 14:47:54 2017 UTC (7 years ago) by mpi
Branch: MAIN
Changes since 1.1: +1 -4 lines
Diff to previous 1.1 (colored)

SPINLOCK_SPIN_HOOK is no more, define our own set of macros.

Prodded by kettenis@ and tedu@

Revision 1.1 / (download) - annotate - [select for diffs], Sat May 27 14:20:39 2017 UTC (7 years ago) by mpi
Branch: MAIN

New mutex and condvar implementations based on futex(2).

Not enabled yet, it needs some SPINLOCK_SPIN_HOOK love and
some bumps.

Tested by many including sthen@ in a bulk.

ok visa@, sthen@, kettenis@, tedu@

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.