TEST(stdio_ext, __fsetlocking_BYCALLER) { // Check if users can use flockfile/funlockfile to protect stdio operations. int old_state = __fsetlocking(stdout, FSETLOCKING_BYCALLER); flockfile(stdout); pthread_t thread; std::atomic<pid_t> pid(0); ASSERT_EQ(0, pthread_create(&thread, nullptr, reinterpret_cast<void* (*)(void*)>(LockingByCallerHelper), &pid)); WaitUntilThreadSleep(pid); funlockfile(stdout); ASSERT_EQ(0, pthread_join(thread, nullptr)); __fsetlocking(stdout, old_state); }
void test() { ASSERT_EQ(0, pthread_mutex_lock(&m.lock)); progress = LOCK_INITIALIZED; tid = 0; pthread_t thread; ASSERT_EQ(0, pthread_create(&thread, NULL, reinterpret_cast<void* (*)(void*)>(MutexWakeupHelper::thread_fn), this)); WaitUntilThreadSleep(tid); ASSERT_EQ(LOCK_WAITING, progress); progress = LOCK_RELEASED; ASSERT_EQ(0, pthread_mutex_unlock(&m.lock)); ASSERT_EQ(0, pthread_join(thread, NULL)); ASSERT_EQ(LOCK_ACCESSED, progress); }