Sponsored Content
Top Forums Programming POSIX - Hot to check if detached thread is still active Post 302234375 by ramen_noodle on Tuesday 9th of September 2008 02:07:34 PM
Old 09-09-2008
Both ways would work for the op. it seems to me one involves creation of a state machine and the other depends on avoiding serialization blocks imposed by pthread_join.
 

10 More Discussions You Might Find Interesting

1. Programming

Multi threading using posix thread library

hi all, can anyone tell me some good site for the mutithreading tutorials, its application, and some code examples. -sushil (2 Replies)
Discussion started by: shushilmore
2 Replies

2. Programming

About Native POSIX Thread Library (NPTL)

Is there anybody has documents about NPTL I wanna study about it , but can't find the documents.... anyone help appreciate :) :) :) (1 Reply)
Discussion started by: alan.zhao
1 Replies

3. Programming

Posix Thread Programming

Hello, i have 2 questions: 1. Can I get the current memory usage of a thread? 2. Can I use a member-function as (void*)(*)(void*) method to create a new thread with "pthread_create(...)"?? I would be happy about any suggestion. Regards, Rolf (2 Replies)
Discussion started by: rkasel
2 Replies

4. Programming

POSIX Thread - Memory leak

Hi all! I am implementing an http server in c++ using the posix thread, but i am having a memory leak and i cannot find the reason. I have already commented out the section that initializes the threads and i found out, the problem is when i initialize/run the threads. In the threads i have... (1 Reply)
Discussion started by: laurovalente
1 Replies

5. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

6. UNIX for Advanced & Expert Users

POSIX thread runs out of memory

i am creating threads in my program using the POSIX interface. when the thread starts executing i run out of memory and get a core dump. i have tried to increase the threads stack size using pthread_attr_setstacksize, but of no use since i guess the dynamic memory is allocated on the heap and... (1 Reply)
Discussion started by: aniketkadu2002
1 Replies

7. Programming

detached thread is causing program crash

Hi All, I have scenario where my callback function data_update() can be called anytime. I have written the function data_update() such that it will create detached thread for processing the data sent to this function. data_update() { pthread_attr_t attr_thread; ... (1 Reply)
Discussion started by: wonderman
1 Replies

8. Programming

when can we destory thread attributes using pthread_attr_destroy() for detached thrd

Hi All, I am creating detached threads using pthread_create(). As we know, we need to pass the thread attribute structure as an argument to the pthread_Create() API. I want to know what is the good time to destroy this thread attributes using pthread_attr_destroy() call. Also, I want to know... (2 Replies)
Discussion started by: wonderman
2 Replies

9. Shell Programming and Scripting

Script to check if Port is Active

is there a better way to check if a port is active on linux and sunos systems? this is currently what I'm using in my script: netstat -an | egrep -i "$PORT" i know this isn't the best way as there could be numbers in that output that has my port number in it but isn't necessarily a... (0 Replies)
Discussion started by: SkySmart
0 Replies

10. Programming

POSIX Thread Help

I want to create a program that creates 2 child process, and each of them creates 2 threads, and each thread prints its thread id. I0ve allread done that the outuput isn't the outuput i want. When a run the following comand "$./a.out | sort -u | wc -l" I have the folowing output 2 $: It should... (3 Replies)
Discussion started by: pharaoh
3 Replies
PTHREAD_JOIN(3P)					     POSIX Programmer's Manual						  PTHREAD_JOIN(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
pthread_join - wait for thread termination SYNOPSIS
#include <pthread.h> int pthread_join(pthread_t thread, void **value_ptr); DESCRIPTION
The pthread_join() function shall suspend execution of the calling thread until the target thread terminates, unless the target thread has already terminated. On return from a successful pthread_join() call with a non-NULL value_ptr argument, the value passed to pthread_exit() by the terminating thread shall be made available in the location referenced by value_ptr. When a pthread_join() returns successfully, the target thread has been terminated. The results of multiple simultaneous calls to pthread_join() specifying the same target thread are unde- fined. If the thread calling pthread_join() is canceled, then the target thread shall not be detached. It is unspecified whether a thread that has exited but remains unjoined counts against {PTHREAD_THREADS_MAX}. RETURN VALUE
If successful, the pthread_join() function shall return zero; otherwise, an error number shall be returned to indicate the error. ERRORS
The pthread_join() function shall fail if: EINVAL The implementation has detected that the value specified by thread does not refer to a joinable thread. ESRCH No thread could be found corresponding to that specified by the given thread ID. The pthread_join() function may fail if: EDEADLK A deadlock was detected or the value of thread specifies the calling thread. The pthread_join() function shall not return an error code of [EINTR]. The following sections are informative. EXAMPLES
An example of thread creation and deletion follows: typedef struct { int *ar; long n; } subarray; void * incer(void *arg) { long i; for (i = 0; i < ((subarray *)arg)->n; i++) ((subarray *)arg)->ar[i]++; } int main(void) { int ar[1000000]; pthread_t th1, th2; subarray sb1, sb2; sb1.ar = &ar[0]; sb1.n = 500000; (void) pthread_create(&th1, NULL, incer, &sb1); sb2.ar = &ar[500000]; sb2.n = 500000; (void) pthread_create(&th2, NULL, incer, &sb2); (void) pthread_join(th1, NULL); (void) pthread_join(th2, NULL); return 0; } APPLICATION USAGE
None. RATIONALE
The pthread_join() function is a convenience that has proven useful in multi-threaded applications. It is true that a programmer could sim- ulate this function if it were not provided by passing extra state as part of the argument to the start_routine(). The terminating thread would set a flag to indicate termination and broadcast a condition that is part of that state; a joining thread would wait on that condi- tion variable. While such a technique would allow a thread to wait on more complex conditions (for example, waiting for multiple threads to terminate), waiting on individual thread termination is considered widely useful. Also, including the pthread_join() function in no way precludes a programmer from coding such complex waits. Thus, while not a primitive, including pthread_join() in this volume of IEEE Std 1003.1-2001 was considered valuable. The pthread_join() function provides a simple mechanism allowing an application to wait for a thread to terminate. After the thread termi- nates, the application may then choose to clean up resources that were used by the thread. For instance, after pthread_join() returns, any application-provided stack storage could be reclaimed. The pthread_join() or pthread_detach() function should eventually be called for every thread that is created with the detachstate attribute set to PTHREAD_CREATE_JOINABLE so that storage associated with the thread may be reclaimed. The interaction between pthread_join() and cancellation is well-defined for the following reasons: * The pthread_join() function, like all other non-async-cancel-safe functions, can only be called with deferred cancelability type. * Cancellation cannot occur in the disabled cancelability state. Thus, only the default cancelability state need be considered. As specified, either the pthread_join() call is canceled, or it succeeds, but not both. The difference is obvious to the application, since either a cancellation handler is run or pthread_join() returns. There are no race conditions since pthread_join() was called in the deferred cancelability state. FUTURE DIRECTIONS
None. SEE ALSO
pthread_create(), wait(), the Base Definitions volume of IEEE Std 1003.1-2001, <pthread.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 PTHREAD_JOIN(3P)
All times are GMT -4. The time now is 04:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy