/* * LTP project test pthread_mutex_lock/1-1.c, modified to trigger * the futex_unlock_pi EAGAIN loopstall, on those kernels having * this bug. * * To build: cc -o 1-1 1-1.c -pthread * To run: taskset 4 ./1-1 * Result: if helper kernel patch is installed, one will get this * in the kernel log: 'WARNING: futex_unlock_pi: in EAGAIN loop'. * This indicates that the EAGAIN loop was seen and broken out of with * a usleep_range(1000,1000). If the helper kernel patch is not present, * 1-1 loops forever in futex_unlock_pi, and is unkillable. * * * * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_lock() * shall lock the mutex object referenced by 'mutex'. If the mutex is * already locked, the calling thread shall block until the mutex becomes * available. This operation shall return with the mutex object referenced * by 'mutex' in the locked state with the calling thread as its owner. * Steps: * -- Initialize a mutex to protect a global variable 'value' * -- Create N threads. Each is looped M times to acquire the mutex, * increase the value, and then release the mutex. * -- Check if the value has increased properly (M*N); a broken mutex * implementation may cause lost augments. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" #define THREAD_NUM 15 #define LOOPS 40000 static void setpri(int priority) { struct sched_param parm; parm.sched_priority = priority; sched_setscheduler(0, SCHED_FIFO, &parm); } void *f1(void *parm); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int value; /* value protected by mutex */ int main(void) { int i, rc __attribute__((unused)); pthread_attr_t pta; pthread_mutexattr_t mta; pthread_t threads[THREAD_NUM]; pthread_attr_init(&pta); pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE); pthread_mutexattr_init(&mta); pthread_mutexattr_setprotocol(&mta, PTHREAD_PRIO_INHERIT); pthread_mutex_init(&mutex, &mta); /* Create threads */ fprintf(stderr,"Creating %d threads\n", THREAD_NUM); fprintf(stderr,"Executing %d loops\n", LOOPS); for (i=0; i