Home | History | Annotate | Download | only in speculative
      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_join()
      9  *
     10  * pthread_join() SHALL fail if:
     11  *
     12  * -[ESRCH] No thread could be found corresponding to that thread ID
     13  *
     14  * pthread_join() MAY fail if:
     15  *
     16  * -[EINVAL] The implementation has detected that the value specified by
     17  *  'thread' does not refer to a joinable thread.
     18  * -[EDEADLK] A deadlock was detected or the value of 'thread' specifies the
     19  *  calling thread.
     20  *
     21  * It shall not return an error code of [EINTR]
     22  *
     23  * Testing EINVAL
     24  *
     25  * Steps:
     26  * 1.  Create a new thread that is non-joinable (i.e. detached state
     27  *     attribute is PTHREAD_CREATE_DETACHED.
     28  * 2.  Call pthread_join() in main.  It should return EINVAL.
     29  *     If not, the test fails.
     30  */
     31 
     32 #include <pthread.h>
     33 #include <stdio.h>
     34 #include <unistd.h>
     35 #include <errno.h>
     36 #include "posixtest.h"
     37 
     38 static void *a_thread_func()
     39 {
     40 	pthread_exit(0);
     41 	return NULL;
     42 }
     43 
     44 int main(void)
     45 {
     46 	pthread_t new_th;
     47 	pthread_attr_t attr;
     48 	int ret;
     49 
     50 	pthread_attr_init(&attr);
     51 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
     52 
     53 	if (pthread_create(&new_th, &attr, a_thread_func, NULL) != 0) {
     54 		perror("Error creating thread\n");
     55 		return PTS_UNRESOLVED;
     56 	}
     57 
     58 	ret = pthread_join(new_th, NULL);
     59 	if (ret != EINVAL) {
     60 		printf("Test FAILED: Return code should be EINVAL, "
     61 		       "but is: %d instead.\n", ret);
     62 		return PTS_FAIL;
     63 	}
     64 
     65 	printf("Test PASSED\n");
     66 	return PTS_PASS;
     67 }
     68