Name

pthread_create
- create a new thread

Library

libc_r.lib libpthread.lib libthr.lib

Synopsis

  #include <pthread.h>
  int pthread_create (pthread_t *threadhdl, const pthread_attr_t *attrib, void *(*begin_routine)(void *), void *param);

Return values

If successful, the pthread_create function will return zero. Otherwise an error number will be returned to indicate the error.

Detailed description

The pthread_create function is used to create a new thread, with attributes specified by attrib, within a process. If attrib is NULL, the default attributes are used. If the attributes specified by attrib are modified later, the thread’s attributes are not affected. Upon successful completion pthread_create will store the ID of the created thread in the location specified by threadhdl.

The thread is created executing begin_routine with param as its sole argument. If the begin_routine returns, the effect is as if there was an implicit call to pthread_exit using the return value of start_routine as the exit status. Note that the thread in which main was originally invoked differs from this. When it returns from main, the effect is as if there was an implicit call to exit using the return value of main as the exit status.


Examples

void *a_thread_func_1_1(void*)
{
 return NULL;
}
int XYZ()
{
 pthread_t new_th;
 if(pthread_create(&new_th, NULL, a_thread_func_1_1, NULL) != 0)
 {
  perror("Error creating thread\n");
  return -1;
 }
}

         

Errors

The pthread_create function will fail if:
[EAGAIN]
  The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process [PTHREAD_THREADS_MAX] would be exceeded.
[EINVAL]
  The value specified by attrib is invalid.

See also

pthread_exit, pthread_join


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top