Re: Is there such a thing as an invalid thread id?



On Thu, 19 Jan 2006 11:36:32 -0800, Buckaroo_Banzi wrote:

> I am creating a threaded application and just wish to return the thread
> id to the calling function. I am looking to let the calling function
> determine if pthread_create worked by the thread id.
>
> I have a feeling that there is a thread id value that indicates an
> invalid thread, such as 0 or -1. Could someone let me know if this is
> true and if so what value indicates an invalid thread?

>From the man page (gentle reminder to RTFM):

SYNOPSIS
#include <pthread.h>

int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void *
arg);


DESCRIPTION
pthread_create creates a new thread of control that executes concurrently with the calling thread. The
new thread applies the function start_routine passing it arg as first argument. The new thread termi-
nates either explicitly, by calling pthread_exit(3), or implicitly, by returning from the start_routine
function. The latter case is equivalent to calling pthread_exit(3) with the result returned by
start_routine as exit code.

The attr argument specifies thread attributes to be applied to the new thread. See pthread_attr_init(3)
for a complete list of thread attributes. The attr argument can also be NULL, in which case default
attributes are used: the created thread is joinable (not detached) and has default (non real-time)
scheduling policy.


RETURN VALUE
On success, the identifier of the newly created thread is stored in the location pointed by the thread
argument, and a 0 is returned. On error, a non-zero error code is returned.


ERRORS
EAGAIN not enough system resources to create a process for the new thread.

EAGAIN more than PTHREAD_THREADS_MAX threads are already active.

.



Relevant Pages

  • Re: using my own malloc()
    ... presume to know what the caller wants to do with the error. ... even calling fprintf could be undesirable. ... Your wrapper function checks for ... calling function doesn't also check, ...
    (comp.lang.c)
  • Re: slightly OT: error handling conventions
    ... > trivially set it to NULL after calling free on it. ... , accessing a pointer after ... I'd say that the calling function MUST NOT make any assumptions about ...
    (comp.lang.c)
  • Re: Timeout implementation
    ... <Harvey Triana/> ... I am calling a procedure in my form which should return within 10 seconds. ... If the procedure takes more time than 10 seconds, the calling function ... I implemented a timer but that didnt work. ...
    (microsoft.public.vb.general.discussion)
  • Re: Proper use of write() on RS-232 serial interface
    ... nonblocking I/O. ... then calling write again in case of ... EAGAIN would be a mistake. ... You would see the code looping getting EAGAIN from ...
    (comp.os.linux.development.apps)
  • Re: Adding attributes stored in a list to a class dynamically.
    ... for attr in attrs: ... What is the difference between calling ... def newAttribute2: ...
    (comp.lang.python)