Imported Upstream version 20080930
[ltp-debian.git] / testcases / realtime / func / pi-tests / testpi-5.c
bloba29c26288dabe72619a28b2d8cee714921315064
1 /******************************************************************************
3 * Copyright © International Business Machines Corp., 2008
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * NAME
20 * testpi-5.c
22 * DESCRIPTION
26 * USAGE:
27 * Use run_auto.sh script in current directory to build and run test.
28 * Use "-j" to enable jvm simulator.
30 * AUTHOR
33 * HISTORY
36 *****************************************************************************/
38 #include <stdio.h>
39 #include <pthread.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <librttest.h>
43 pthread_mutex_t child_mutex;
45 void* child_thread (void* arg)
47 int ret;
49 ret = pthread_mutex_lock(&child_mutex);
50 if (ret != 0)
51 printf("child thread: Failed to lock child_mutex: %d\n", ret);
52 else
53 printf("child_thread: got lock\n");
55 sleep(2);
57 printf("child_thread: Trying to get lock 2nd time\n");
58 ret = pthread_mutex_lock(&child_mutex);
59 if (ret != 0)
60 printf("child thread: Failed to lock child_mutex: %d\n", ret);
61 else
62 printf("child_thread: got lock 2nd time !!\n");
64 return NULL;
67 int do_test(int argc, char ** argv)
69 pthread_mutexattr_t mutexattr;
70 int retc, protocol;
72 if (pthread_mutexattr_init(&mutexattr) != 0) {
73 printf("Failed to init mutexattr\n");
75 if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT) != 0) {
76 printf("Can't set protocol prio inherit\n");
78 if (pthread_mutexattr_getprotocol(&mutexattr, &protocol) != 0) {
79 printf("Can't get mutexattr protocol\n");
80 } else {
81 printf("protocol in mutexattr is %d\n", protocol);
83 if ((retc = pthread_mutex_init(&child_mutex, &mutexattr)) != 0) {
84 printf("Failed to init mutex: %d\n", retc);
87 create_other_thread(child_thread, NULL);
88 join_threads();
90 return 0;
93 #include "test-skeleton.c"