Page MenuHomeFreeBSD

Add pthread_peekjoin_np(3).
ClosedPublic

Authored by kib on Feb 13 2020, 11:46 PM.

Details

Summary

See man page for details. In short, the function allows to peek at the thread exit status and even see return value, without joining the target.

I wrote some tests for cancellation and needed a way to non-destructively see the exit state of the thread.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 29367

Event Timeline

kib created this revision.Feb 13 2020, 11:46 PM
kib updated this revision to Diff 68292.Feb 13 2020, 11:47 PM

Add context.

markj added a comment.Feb 14 2020, 5:46 PM

I see that Linux has a non-blocking join, pthread_tryjoin_np(). Is that not sufficient for your purposes?

share/man/man3/pthread_join.3
40

Maybe "inspect thread termination state"?

98

"If the thread has not exited, the ..."

155

"did not yet exit" or "has not yet exited". I think the second one is more consistent with the rest of the man page.

kib marked 3 inline comments as done.Feb 14 2020, 6:54 PM

I see that Linux has a non-blocking join, pthread_tryjoin_np(). Is that not sufficient for your purposes?

The tryjoin() method joins, while peekjoin() keeps the thread unjoined, which allows to peek or join again. The use for me was to see whether the thread exited, without disrupting an existing code that joined.

Our timedjoin() can be used as tryjoin() by providing the time in past. I can implement tryjoin() as well, if it is considered worth having explicit interface, to be source-compatible with Linux.

kib updated this revision to Diff 68334.Feb 14 2020, 6:55 PM

Man page edits.
Add symlink for man.

markj accepted this revision.Feb 14 2020, 7:29 PM
In D23676#520058, @kib wrote:

I see that Linux has a non-blocking join, pthread_tryjoin_np(). Is that not sufficient for your purposes?

The tryjoin() method joins, while peekjoin() keeps the thread unjoined, which allows to peek or join again. The use for me was to see whether the thread exited, without disrupting an existing code that joined.
Our timedjoin() can be used as tryjoin() by providing the time in past. I can implement tryjoin() as well, if it is considered worth having explicit interface, to be source-compatible with Linux.

Ok. I don't really think it's necessary to implement the Linux extension without some candidate consumer. I was more just wondering how exactly your tests rely on the non-destructive behaviour of peekjoin.

This revision is now accepted and ready to land.Feb 14 2020, 7:29 PM
kib added a comment.Feb 14 2020, 7:50 PM

It was a test for r357894. The victim thread exiting, then I need to wait for it to exit but not join, to issue cancellation request.

This revision was automatically updated to reflect the committed changes.