Fix some issues

This commit is contained in:
Justine Tunney 2023-10-09 20:18:48 -07:00
parent 211d5d902e
commit 9d372f48dd
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
29 changed files with 373 additions and 63 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
@ -26,6 +27,7 @@
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
#include "libc/thread/thread2.h"
@ -283,3 +285,28 @@ TEST(pthread_cancel, self_asynchronous_takesImmediateEffect) {
ASSERT_SYS(0, 0, close(pfds[1]));
ASSERT_SYS(0, 0, close(pfds[0]));
}
atomic_bool was_completed;
void WaitUntilReady(void) {
while (!ready) pthread_yield();
ASSERT_EQ(0, errno);
ASSERT_SYS(0, 0, usleep(1000));
}
void *SleepWorker(void *arg) {
pthread_setcancelstate(PTHREAD_CANCEL_MASKED, 0);
ready = true;
ASSERT_SYS(ECANCELED, -1, usleep(30 * 1e6));
was_completed = true;
return 0;
}
TEST(pthread_cancel, canInterruptSleepOperation) {
pthread_t th;
ASSERT_EQ(0, pthread_create(&th, 0, SleepWorker, 0));
WaitUntilReady();
ASSERT_EQ(0, pthread_cancel(th));
ASSERT_EQ(0, pthread_join(th, 0));
ASSERT_TRUE(was_completed);
}