mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 16:52:28 +00:00
Iterate more on recent changes
This commit is contained in:
parent
7138399f96
commit
d0ad2694ed
22 changed files with 90 additions and 158 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/log/check.h"
|
||||
|
@ -33,6 +34,8 @@ void OnUsr1(int sig) {
|
|||
}
|
||||
|
||||
void SetUpOnce(void) {
|
||||
sigset_t ss;
|
||||
sigprocmask(SIG_SETMASK, 0, &ss);
|
||||
ASSERT_SYS(0, 0, pledge("stdio proc", 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
// create a bunch of threads with nsync semaphore waiter objects
|
||||
// then fork and verify that unlocking in child safely cleans up
|
||||
// this test matters on netbsd, where waiters have a file number
|
||||
|
||||
#define N 10
|
||||
|
||||
pthread_t thread[N];
|
||||
atomic_uint countdown = N;
|
||||
atomic_uint final_countdown = N;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void *WaitWorker(void *arg) {
|
||||
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||
--countdown;
|
||||
ASSERT_EQ(0, pthread_cond_wait(&cond, &lock));
|
||||
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||
--final_countdown;
|
||||
ASSERT_EQ(0, pthread_cond_wait(&cond, &lock));
|
||||
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(mu_semaphore_sem, test) {
|
||||
for (int i = 0; i < N; ++i) {
|
||||
ASSERT_EQ(0, pthread_create(thread + i, 0, WaitWorker, 0));
|
||||
}
|
||||
while (countdown) pthread_yield();
|
||||
SPAWN(fork);
|
||||
CheckForFileLeaks();
|
||||
EXITS(0);
|
||||
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||
ASSERT_EQ(0, pthread_cond_broadcast(&cond));
|
||||
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||
while (final_countdown) pthread_yield(); // make extra sure still works
|
||||
ASSERT_EQ(0, pthread_mutex_lock(&lock));
|
||||
ASSERT_EQ(0, pthread_cond_broadcast(&cond));
|
||||
ASSERT_EQ(0, pthread_mutex_unlock(&lock));
|
||||
for (int i = 0; i < N; ++i) {
|
||||
ASSERT_EQ(0, pthread_join(thread[i], 0));
|
||||
}
|
||||
CheckForFileLeaks();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue