* winsup.api/pthread/mutex8e.c: New testcase.
* winsup.api/pthread/mutex8n.c: Ditto. * winsup.api/pthread/mutex8r.c: Ditto.
This commit is contained in:
parent
b95ae50461
commit
a6435f99ea
|
@ -1,3 +1,9 @@
|
|||
2004-03-04 Thomas Pfaff <tpfaff@gmx.net>
|
||||
|
||||
* winsup.api/pthread/mutex8e.c: New testcase.
|
||||
* winsup.api/pthread/mutex8n.c: Ditto.
|
||||
* winsup.api/pthread/mutex8r.c: Ditto.
|
||||
|
||||
2003-12-23 Christopher Faylor <cgf@redhat.com>
|
||||
|
||||
* winsup.api/pthread/rwlock7.c (main): Don't assume that result of rand
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* mutex8e.c
|
||||
*
|
||||
* Tests PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP.
|
||||
*
|
||||
* Depends on API functions:
|
||||
* pthread_mutex_lock()
|
||||
* pthread_mutex_unlock()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP);
|
||||
|
||||
assert(pthread_mutex_lock(&mutex) == 0);
|
||||
|
||||
assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP);
|
||||
|
||||
assert(mutex != NULL);
|
||||
|
||||
assert(pthread_mutex_lock(&mutex) == EDEADLK);
|
||||
|
||||
assert(pthread_mutex_unlock(&mutex) == 0);
|
||||
|
||||
assert(pthread_mutex_destroy(&mutex) == 0);
|
||||
|
||||
assert(mutex == NULL);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* mutex8n.c
|
||||
*
|
||||
* Tests PTHREAD_NORMAL_MUTEX_INITIALIZER_NP.
|
||||
* Thread locks mutex twice (recursive lock).
|
||||
* The thread should deadlock.
|
||||
*
|
||||
* Depends on API functions:
|
||||
* pthread_create()
|
||||
* pthread_mutex_init()
|
||||
* pthread_mutex_lock()
|
||||
* pthread_mutex_unlock()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static int lockCount = 0;
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_NORMAL_MUTEX_INITIALIZER_NP;
|
||||
|
||||
void * locker(void * arg)
|
||||
{
|
||||
assert(pthread_mutex_lock(&mutex) == 0);
|
||||
lockCount++;
|
||||
|
||||
/* Should wait here (deadlocked) */
|
||||
assert(pthread_mutex_lock(&mutex) == 0);
|
||||
lockCount++;
|
||||
assert(pthread_mutex_unlock(&mutex) == 0);
|
||||
|
||||
return (void *) 555;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
pthread_t t;
|
||||
|
||||
assert(pthread_create(&t, NULL, locker, NULL) == 0);
|
||||
|
||||
Sleep(1000);
|
||||
|
||||
assert(lockCount == 1);
|
||||
|
||||
/*
|
||||
* Should succeed even though we don't own the lock
|
||||
* because FAST mutexes don't check ownership.
|
||||
*/
|
||||
assert(pthread_mutex_unlock(&mutex) == 0);
|
||||
|
||||
Sleep (1000);
|
||||
|
||||
assert(lockCount == 2);
|
||||
|
||||
exit(0);
|
||||
|
||||
/* Never reached */
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* mutex8r.c
|
||||
*
|
||||
* Tests PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP.
|
||||
*
|
||||
* Depends on API functions:
|
||||
* pthread_mutex_lock()
|
||||
* pthread_mutex_unlock()
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
|
||||
|
||||
assert(pthread_mutex_lock(&mutex) == 0);
|
||||
|
||||
assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
|
||||
|
||||
assert(mutex != NULL);
|
||||
|
||||
assert(pthread_mutex_lock(&mutex) == 0);
|
||||
|
||||
assert(pthread_mutex_unlock(&mutex) == 0);
|
||||
|
||||
assert(pthread_mutex_unlock(&mutex) == 0);
|
||||
|
||||
assert(pthread_mutex_destroy(&mutex) == 0);
|
||||
|
||||
assert(mutex == NULL);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue