Make detached threads work better

This change adds a double linked list of threads, so that pthread_exit()
will know when it should call exit() from an orphaned child. This change
also improves ftrace and strace logging.
This commit is contained in:
Justine Tunney 2022-11-09 03:58:57 -08:00
parent b74d8c1acd
commit cee6871710
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
37 changed files with 638 additions and 314 deletions

View file

@ -16,18 +16,27 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/assert.h"
#include "libc/intrin/atomic.h"
#include "libc/thread/posixthread.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
/**
* Sets value of TLS slot for current thread.
*
* If `k` wasn't created by pthread_key_create() then the behavior is
* undefined. If `k` was unregistered earlier by pthread_key_delete()
* then the behavior is undefined.
*/
int pthread_setspecific(pthread_key_t key, const void *val) {
if (0 <= key && key < PTHREAD_KEYS_MAX) {
__get_tls()->tib_keys[key] = val;
return 0;
} else {
return EINVAL;
}
int pthread_setspecific(pthread_key_t k, const void *val) {
// "The effect of calling pthread_getspecific() or
// pthread_setspecific() with a key value not obtained from
// pthread_key_create() or after key has been deleted with
// pthread_key_delete() is undefined."
// ──Quoth POSIX.1-2017
_unassert(0 <= k && k < PTHREAD_KEYS_MAX);
_unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire));
__get_tls()->tib_keys[k] = val;
return 0;
}