Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pthread_attr_setdetachstate(3) [netbsd man page]

PTHREAD_ATTR_GETDETACHSTATE(3)				   BSD Library Functions Manual 			    PTHREAD_ATTR_GETDETACHSTATE(3)

NAME
pthread_attr_getdetachstate -- get and set the ``detach state'' attribute LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); DESCRIPTION
The attribute parameters for the pthread_attr_getdetachstate() and pthread_attr_setdetachstate() functions are mutually exclusive and must be one of: PTHREAD_CREATE_JOINABLE The threads must explicitly be waited for using the pthread_join(3) function once they exit for their status to be received and their resources to be freed. This is the default. PTHREAD_CREATE_DETACHED The thread's resources will automatically be freed once the thread exits, and the thread will not be joined. If the thread is created as detached, it is an error to use the thread ID with pthread_detach(3) or pthread_join(3). RETURN VALUES
If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. ERRORS
No errors are defined for pthread_attr_getdetachstate(). The pthread_attr_setdetachstate() function should fail if: [EINVAL] The value specified by detachstate is invalid. SEE ALSO
pthread_attr(3), pthread_detach(3), pthread_join(3) STANDARDS
Both functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
July 9, 2010 BSD

Check Out this Related Man Page

PTHREAD_ATTR(3) 					   BSD Library Functions Manual 					   PTHREAD_ATTR(3)

NAME
pthread_attr_getdetachstate, pthread_attr_setdetachstate -- thread attribute operations SYNOPSIS
#include <pthread.h> int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); DESCRIPTION
Thread attributes are used to specify parameters to pthread_create(). One attribute object can be used in multiple calls to pthread_create(), with or without modifications between calls. One of these thread attributes governs the creation state of the new thread. The new thread can be either created "detached" or "joinable". The constants corresponding to these states are PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE respectively. Creating a "joinable" thread allows the user to call pthread_join() and pthread_detach(), with the new thread's ID. A "detached" thread's ID cannot be used with pthread_join() and pthread_detach(). The default value for the "detachstate" attribute is PTHREAD_CREATE_JOINABLE. The pthread_attr_setdetachstate() function sets the thread's "detachstate" attribute. The "detachstate" attribute is set within the attr argument, which can subsequently be used as an argument to pthread_create(). RETURN VALUES
If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. pthread_attr_getdetachstate(), on success, will copy the value of the thread's "detachstate" attribute to the location pointed to by the second function parameter. ERRORS
pthread_attr_getdetachstate() will fail if: [EINVAL] Invalid value for attr pthread_attr_setdetachstate() will fail if: [EINVAL] Invalid value for attr or detachstate. SEE ALSO
pthread_create(3), pthread_join(3), pthread_attr_init(3), pthread_detach(3) STANDARDS
pthread_attr_setdetachstate(), pthread_attr_getdetachstate() conform to ISO/IEC 9945-1:1996 (``POSIX.1'') BSD
December 31, 2007 BSD
Man Page

11 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

2. Programming

Memory LEAK with pthreads

I have this code... #include <stdio.h> #include <iostream> #include <pthread.h> static void* cliente(void *datos); int main() { pthread_attr_t tattr; int ret; size_t size = PTHREAD_STACK_MIN + 0x0100; ret = pthread_attr_init(&tattr); ret =... (8 Replies)
Discussion started by: JEscola
8 Replies

3. Programming

Compilation Error

I am getting the below given errors for the following program though all the variables have been declared and used appropriately. Please Help. The environment is AIX. Error: ------ "gbsizeprofile.c", line 67.4: 1506-275 (S) Unexpected text 'void' encountered. "gbsizeprofile.c", line 67.10:... (2 Replies)
Discussion started by: yschd
2 Replies

4. Programming

How to use sigmask in order to make signals can be processed by a thread

Hi, I have a UDP server and client program, and they must run within a program, so I decided two threads, one for UDP server and another for UDP client. The simple architecture is shown in attachment. However, I can't send the packets out on the UDP client, no any time message and... (2 Replies)
Discussion started by: sehang
2 Replies

5. Programming

Multi-threading

In this piece i implemented the gossip method. The first thread is invoked from inside the (msg is first sent from node -1 to 0 from main()) and the other threads are invoked from inside of the thread function itself. I used two mutexes and a condition variable to control the synchronization. ... (4 Replies)
Discussion started by: saman_glorious
4 Replies

6. Programming

unable to use a function to crate a joinable thread

In my program, threads may be created when some events trigger. So I can't create threads on initialization. Theremore,I write a createThread() function to create thread. However, it is blocking at first call and don't run anymore? why? #include <pthread.h> #include <stdio.h> #include... (4 Replies)
Discussion started by: sehang
4 Replies

7. Programming

Thread parameter in ANSI C makes a segmentation fault

The creation of thread. void Client_Constructor ( const char* IPAddr ) { pthread_t tid; pthread_attr_t rx; /* Create separate memory for client argument */ struct ThreadArgs *threadArgs; if ( ( threadArgs = ( struct ThreadArgs* ) malloc( sizeof( struct ThreadArgs )... (14 Replies)
Discussion started by: sehang
14 Replies

8. UNIX for Advanced & Expert Users

Pthread attr setting doesn't work before thread create?

Hello everyone, I created a test program for pthread priority set. Here's the code, very simple, 60 lines only. I've tried this prog on my Fedora 13(on vbox), and on my 6410 arm linux 2.6.36. Both the same result. Both environments are using root privileges. Can any body tells me why the... (15 Replies)
Discussion started by: ss1969
15 Replies

9. Programming

Understanding Condition variables

I am trying the understand the conditional variable concept. I went through the following site: https://computing.llnl.gov/tutorials/pthreads/#ConditionVariables I understand that condition variables allow threads to synchronize based upon the VALUE of data. When the data acheives a particular... (2 Replies)
Discussion started by: rupeshkp728
2 Replies

10. Programming

Multiple instances of pthread

Suppose I declare pthread_t clear_thread; and then pthread_create(&clear_thread, &detach, clear_message, this); the thread is supposed to go away, perform the service it is intended to procide, and then kill itself. A little while later, I require this service again, so I say ... (2 Replies)
Discussion started by: clerew
2 Replies

11. Homework & Coursework Questions

Bounded Buffer is hanging, tried all I can. (C++)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: My problem is that when creating my producers and consumers, if I don't create an equal number of both, the... (12 Replies)
Discussion started by: digitalbrainiac
12 Replies