mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Fix some issues
This commit is contained in:
parent
211d5d902e
commit
9d372f48dd
29 changed files with 373 additions and 63 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue