1/*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by:  rolla.n.selbak REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 * Test that pthread_create() creates a new thread with attributes specified
9 * by 'attr', within a process.
10 *
11 * Steps:
12 * 1.  Create a thread using pthread_create()
13 * 2.  Cancel that thread with pthread_cancel()
14 * 3.  If that thread doesn't exist, then it pthread_cancel() will return
15 *     an error code.  This would mean that pthread_create() did not create
16 *     a thread successfully.
17 */
18
19#include <pthread.h>
20#include <stdio.h>
21#include <unistd.h>
22#include "posixtest.h"
23
24void *a_thread_func()
25{
26	sleep(10);
27
28	/* Shouldn't reach here.  If we do, then the pthread_cancel()
29	 * function did not succeed. */
30	perror("Could not send cancel request correctly\n");
31	pthread_exit(0);
32	return NULL;
33}
34
35int main()
36{
37	pthread_t new_th;
38
39	if(pthread_create(&new_th, NULL, a_thread_func, NULL) < 0)
40	{
41		perror("Error creating thread\n");
42		return PTS_UNRESOLVED;
43	}
44
45	/* Try to cancel the newly created thread.  If an error is returned,
46	 * then the thread wasn't created successfully. */
47	if(pthread_cancel(new_th) != 0)
48	{
49		printf("Test FAILED: A new thread wasn't created\n");
50		return PTS_FAIL;
51	}
52
53	printf("Test PASSED\n");
54	return PTS_PASS;
55}
56
57
58