os/ossrv/genericopenlibs/openenvcore/libpthread/inc/pthread.dosc
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /** @file ../inc/pthread.h
     2 @internalComponent
     3 */
     4 
     5 /** @def POSIX_THREAD_KEYS_MAX
     6 
     7 Represents maximum value
     8 
     9 @publishedAll
    10 @externallyDefinedApi
    11 */
    12 
    13 /** @def PTHREAD_STACK_MIN  
    14 
    15 Minimum supported stack size for a thread
    16                  
    17 @publishedAll
    18 @externallyDefinedApi
    19 */
    20 
    21 /** @def POSIX_THREAD_THREADS_MAX            
    22 
    23 Thread max. Value is 64
    24 
    25 @publishedAll
    26 @externallyDefinedApi
    27 */
    28 
    29 /** @def PTHREAD_THREADS_MAX
    30 
    31 Maximum number of threads supported per process. Value is 1024
    32 
    33 @publishedAll
    34 @externallyDefinedApi
    35 */
    36 
    37 /** @def SEM_VALUE_MAX
    38 
    39 Semaphores have a maximum value past which they cannot be incremented. The macro SEM_VALUE_MAX is defined to be this maximum value.
    40 
    41 @publishedAll
    42 @externallyDefinedApi
    43 */
    44 
    45 /** @def PTHREAD_COND_INITIALIZER
    46 
    47 Value is 4. Describes condition initializer.
    48 
    49 @publishedAll
    50 @externallyDefinedApi
    51 */
    52 
    53 /** @def SEM_NSEMS_MAX          
    54 
    55 The maximum number of semaphores a process can have.value is 1024
    56              
    57 @publishedAll
    58 @released
    59 */
    60 
    61 /** @def POSIX_SEM_NSEMS_MAX       
    62 
    63 Number of semaphores a process can have. 
    64           
    65 @publishedAll
    66 @released
    67 */
    68 
    69 /** @def POSIX_THREAD_DESTRUCTOR_ITERATIONS  
    70 
    71 Controlling the iterations of destructors for thread-specific data.
    72 
    73 @publishedAll
    74 @released
    75 */
    76 
    77 /** @typedef typedef int pthread_once_t
    78 
    79 Used for dynamic package initialization.
    80 
    81 @publishedAll
    82 @externallyDefinedApi
    83 */
    84 
    85 /** @typedef typedef struct _pthread_condattr_t*   pthread_condattr_t
    86 
    87 Used to identify a condition attribute object
    88 
    89 @publishedAll
    90 @externallyDefinedApi
    91 */
    92 
    93 /** @struct pthread_mutex_t 
    94 
    95 Thread mutex type. Used for mutexes.
    96 
    97 @publishedAll
    98 @externallyDefinedApi
    99 */
   100 
   101 /** @struct pthread_mutexattr_t
   102 
   103 Used to identify a mutex attribute object. 
   104 
   105 @publishedAll
   106 @externallyDefinedApi
   107 */
   108 
   109 /** @struct pthread_cond_t
   110 
   111 Used for condition variables. 
   112 
   113 @publishedAll
   114 @externallyDefinedApi
   115 */
   116 
   117 /** @fn  pthread_create(pthread_t *threadhdl, pthread_attr_t *attrib, thread_begin_routine begin_routine, void *param)
   118 @param threadhdl
   119 @param attrib
   120 @param begin_routine
   121 @param *param
   122 @return   If successful, the pthread_create function will return zero.
   123 Otherwise an error number will be returned to
   124 indicate the error.
   125 
   126   The pthread_create function is used to create a new thread, with attributes specified by attrib ,
   127 within a process.
   128 If attrib is NULL ,
   129 the default attributes are used.
   130 If the attributes specified by attrib are modified later, the thread's attributes are not affected.
   131 Upon
   132 successful completion pthread_create will store the ID of the created thread in the location specified by threadhdl .
   133 
   134  The thread is created executing begin_routine with param as its sole argument.
   135 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.
   136 Note that the thread in which main was originally invoked differs from this.
   137 When it returns from main ,
   138 the effect is as if there was an implicit call to exit using the return value of main as the exit status.
   139 
   140 
   141 
   142 Examples:
   143 @code
   144 void *a_thread_func_1_1(void*)
   145 {
   146  return NULL;
   147 }
   148 int XYZ()
   149 {
   150  pthread_t new_th;
   151  if(pthread_create(&new;_th, NULL, a_thread_func_1_1, NULL) != 0)
   152  {
   153   perror("Error creating thread
   154 ");
   155   return -1;
   156  }
   157 }
   158 
   159 @endcode
   160 @see pthread_exit()
   161 @see pthread_join()
   162 
   163 
   164  
   165 
   166 @publishedAll
   167 @externallyDefinedApi
   168 */ 
   169 
   170 /** @fn  pthread_self(void)
   171 
   172 @return   The pthread_self function returns the thread ID of the calling thread.
   173 
   174   The pthread_self function returns the thread ID of the calling thread.
   175 
   176 
   177 
   178 Examples:
   179 @code
   180 pthread_t new_th2;
   181 new_th2=pthread_self();
   182 
   183 @endcode
   184 @see pthread_create()
   185 @see pthread_equal()
   186 
   187 
   188  
   189 
   190 @publishedAll
   191 @externallyDefinedApi
   192 */                    
   193 
   194 /** @fn  pthread_equal(pthread_t t1, pthread_t t2)
   195 @param t1
   196 @param t2
   197 @return   The pthread_equal function will return non-zero if the thread IDs t1 and t2 correspond to the same thread, otherwise it will return zero.
   198 
   199   The pthread_equal function compares the thread IDs t1 and t2 .
   200 
   201 Examples:
   202 @code
   203 void *a_thread_func_1_2(void*)
   204 {
   205  pthread_exit(0);
   206  return NULL;
   207 }
   208 void XYZ()
   209 {
   210 pthread_t new_th1, new_th2;
   211  /* Create a new thread. */
   212  if(pthread_create(&new;_th1, NULL, a_thread_func_1_2, NULL) != 0)
   213  {
   214   perror("Error creating thread
   215 ");
   216   return -1;
   217  }
   218  /* Create another new thread. */
   219  if(pthread_create(&new;_th2, NULL, a_thread_func_1_2, NULL) != 0)
   220  {
   221   perror("Error creating thread
   222 ");
   223   return -1;
   224  }
   225  /* Call pthread_equal() and pass to it the 2 new threads.
   226   * It should return a zero value, indicating that
   227   * they are not equal. */
   228  if(pthread_equal(new_th1, new_th2) != 0)
   229  {
   230   printf("pthread_equal FAILED
   231 ");
   232   return -1;
   233  }
   234 }
   235 
   236 @endcode
   237 @see pthread_create()
   238 @see pthread_exit()
   239 
   240 
   241  
   242 
   243 @publishedAll
   244 @externallyDefinedApi
   245 */
   246 
   247 /** @fn  pthread_join(pthread_t thrHandle, void **retValPtr)
   248 @param thrHandle
   249 @param retValPtr
   250 @return   If successful, the pthread_join function will return zero.
   251 Otherwise an error number will be returned to
   252 indicate the error.
   253 
   254   The pthread_join function suspends execution of the calling thread until the target thrHandle terminates unless the target thrHandle has already terminated.
   255 
   256  On return from a successful pthread_join call with a non-NULL retValPtr argument, the value passed to pthread_exit by the terminating thread is stored in the location referenced by retValPtr .
   257 When a pthread_join returns successfully, the target thread has been terminated.
   258 The results
   259 of multiple simultaneous calls to pthread_join specifying the same target thread are undefined.
   260 
   261 
   262 
   263 Examples:
   264 @code
   265 /* Thread's function. */
   266 void *a_thread_func_1_1(void*)
   267 {
   268  int i;
   269  printf("Wait for 3 seconds for thread to finish execution:0);
   270  for(i=1;i<4;i++)
   271  {
   272   printf("Waited (%d) second0, i);
   273   sleep(1);
   274  }
   275  return NULL;
   276 }
   277 int XYZ()
   278 {
   279  pthread_t new_th;
   280  /* Create a new thread. */
   281  if(pthread_create(&new;_th, NULL, a_thread_func_1_1, NULL) != 0)
   282  {
   283   perror("Error creating thread
   284 ");
   285   return -1;
   286  }
   287  /* Wait for thread to return */
   288  if(pthread_join(new_th, NULL) != 0)
   289  {
   290   perror("Error in pthread_join()
   291 ");
   292   return -1;
   293  }
   294 
   295 @endcode
   296 @see wait()
   297 @see pthread_create()
   298 
   299 
   300  
   301 
   302 @publishedAll
   303 @externallyDefinedApi
   304 */
   305 
   306 /** @fn  pthread_detach(pthread_t thrHandle)
   307 @param thrHandle
   308 @return   If successful, the pthread_detach function will return zero.
   309 Otherwise an error number will be returned to
   310 indicate the error.
   311 
   312   The pthread_detach function is used to indicate to the implementation that storage for the
   313 thread thrHandle can be reclaimed when the thread terminates.
   314 If thrHandle has not terminated, pthread_detach will not cause it to terminate.
   315 The effect of multiple pthread_detach calls on the same target thread is unspecified.
   316 
   317 Examples:
   318 @code
   319 void *a_thread_func_1_1(void*)
   320 {
   321  sleep(10);
   322  return NULL;
   323 }
   324 int main_1_1()
   325 {
   326  pthread_attr_t new_attr;
   327  pthread_t new_th;
   328  int ret;
   329  /* Initialize attribute */
   330  if(pthread_attr_init(&new;_attr) != 0)
   331  {
   332   perror("Cannot initialize attribute object
   333 ");
   334   return -1;
   335  }
   336  /* Set the attribute object to be joinable */
   337  if(pthread_attr_setdetachstate(&new;_attr, PTHREAD_CREATE_JOINABLE) != 0)
   338  {
   339   perror("Error in pthread_attr_setdetachstate()
   340 ");
   341   return -1;
   342  }
   343  /* Create the thread */
   344  if(pthread_create(&new;_th, &new;_attr, a_thread_func_1_1, NULL) != 0)
   345  {
   346   perror("Error creating thread
   347 ");
   348   return -1;
   349  }
   350  /* Detach the thread. */
   351  if(pthread_detach(new_th) != 0)
   352  {
   353   printf("Error detaching thread
   354 ");
   355   return -1;
   356  }
   357 
   358 @endcode
   359 @see pthread_join()
   360 
   361 
   362  
   363 
   364 @publishedAll
   365 @externallyDefinedApi
   366 */
   367 
   368 /** @fn  pthread_exit(void *retValPtr)
   369 @param retValPtr
   370 @return   The pthread_exit function cannot return to its caller.
   371 
   372   The pthread_exit function terminates the calling thread and makes the value retValPtr available to any successful join with the terminating thread.
   373 Thread termination does not release any application
   374 visible process resources, including, but not limited to, mutexes and
   375 file descriptors, nor does it perform any process level cleanup
   376 actions, including, but not limited to, calling atexit routines that may exist.
   377 
   378  An implicit call to pthread_exit is made when a thread other than the thread in which main was first invoked returns from the start routine that was used to create
   379 it.
   380 The function's return value serves as the thread's exit status.
   381 
   382  The behavior of pthread_exit is undefined if called from a cancellation handler or destructor function
   383 that was invoked as the result of an implicit or explicit call to pthread_exit .
   384 
   385  After a thread has terminated, the result of access to local (auto)
   386 variables of the thread is undefined.
   387 Thus, references to local variables
   388 of the exiting thread should not be used for the pthread_exit retValPtr parameter value.
   389 
   390  The process will exit with an exit status of 0 after the last thread has
   391 been terminated.
   392 The behavior is as if the implementation called exit with a zero argument at thread termination time.
   393 
   394 Examples:
   395 @code
   396 /* Thread's function. */
   397 void *a_thread_func_1_1(void*)
   398 {
   399  /* .. Do some thing .. */
   400  pthread_exit((void*)RETURN_CODE);
   401 }
   402 
   403 @endcode
   404 @see _exit()
   405 @see exit()
   406 @see pthread_create()
   407 @see pthread_join()
   408 
   409 
   410  
   411 
   412 @publishedAll
   413 @externallyDefinedApi
   414 */
   415  
   416 /** @fn  pthread_attr_init(pthread_attr_t *attrib)
   417 @param attrib
   418 
   419 Note: This description also covers the following functions -
   420  pthread_attr_destroy()  pthread_attr_setstacksize()  pthread_attr_getstacksize()  pthread_attr_setdetachstate()  pthread_attr_getdetachstate()  pthread_attr_setschedparam()  pthread_attr_getschedparam()  pthread_attr_setschedpolicy()  pthread_attr_getschedpolicy()  pthread_attr_setscope()  pthread_attr_getscope() 
   421 
   422 @return   If successful, these functions return 0.
   423 Otherwise, an error number is returned to indicate the error.
   424 
   425   Thread attributes are used to specify parameters to pthread_create .
   426 One attribute object can be used in multiple calls to pthread_create ,
   427 with or without modifications between calls.
   428 
   429  The pthread_attr_init function initializes attrib with all the default thread attributes.
   430 
   431  The pthread_attr_destroy function destroys attrib .
   432 
   433  The pthread_attr_set* functions set the attribute that corresponds to each function name.
   434 
   435  The pthread_attr_get* functions copy the value of the attribute that corresponds to each function name
   436 to the location pointed to by the second function parameter.
   437 
   438 Examples:
   439 @code
   440 /* ***************************************************** */
   441 /* Example for pthread_attr_init & pthread_attr_destroy  */
   442 /* ***************************************************** */
   443 pthread_attr_t new_attr;
   444 /* Initialize attribute */
   445 if(pthread_attr_init(&new;_attr) != 0)
   446 {
   447   printf("Cannot initialize attribute object
   448 ");
   449   return -1; /* or exit */
   450 }
   451 /* Create thread */
   452 /* Destroy attribute */
   453 if(pthread_attr_destroy(&new;_attr) != 0)
   454 {
   455   perror("Cannot destroy the attribute object
   456 ");
   457   return -1; /* or exit*/
   458 }
   459 
   460 @endcode
   461 @code
   462 /* ***************************************************** */
   463 /* Example for pthread_attr_getdetachstate               */
   464 /* ***************************************************** */
   465 pthread_attr_t new_attr;
   466 int detach_state;
   467 /* Initialize attribute */
   468 if(pthread_attr_init(&new;_attr) != 0)
   469 {
   470   printf("Cannot initialize attribute object
   471 ");
   472   return -1;
   473 }
   474 if(pthread_attr_getdetachstate(&new;_attr, &detach;_state) != 0)
   475 {
   476   printf("Cannot get the state
   477 ");
   478   return -1;
   479 }
   480 if(detach_state == PTHREAD_CREATE_JOINABLE)
   481 {
   482   printf("State is joinable 
   483 ");
   484 }
   485 else
   486 {
   487   printf("State is detached 
   488 ");
   489 }
   490 /* Create thread */
   491 /* Destroy attribute */
   492 
   493 @endcode
   494 @code
   495 /* ***************************************************** */
   496 /* Example for pthread_attr_getschedpolicy               */
   497 /* ***************************************************** */
   498 pthread_attr_t new_attr;
   499 int rc;
   500 int policy;
   501 /* Initialize attribute */
   502 if(pthread_attr_init(&new;_attr) != 0)
   503 {
   504   printf("Cannot initialize attribute object
   505 ");
   506   return -1; /* or exit */
   507 }
   508 rc = pthread_attr_getschedpolicy(new_attr, &policy;);
   509 if( rc != 0) {
   510   printf("pthread_attr_getschedpolicy failed
   511 ");
   512   return -1;
   513 }
   514 switch(policy) {
   515  case SCHED_FIFO:
   516        printf("Scheduling policy: SCHED_FIFO 0);
   517        break;
   518  case SCHED_RR:
   519        printf("Scheduling policy: SCHED_RR 
   520 ");
   521        break;
   522  case SCHED_OTHER:
   523        printf("Scheduling policy: SCHED_OTHER 
   524 ");
   525        break;
   526 }
   527 /* Create thread */
   528 /* Destroy attribute */
   529 
   530 @endcode
   531 @code
   532 /* ***************************************************** */
   533 /* Example for pthread_attr_getscope                     */
   534 /* ***************************************************** */
   535 pthread_attr_t new_attr;
   536 int rc;
   537 int scope;
   538 /* Initialize attribute */
   539 if(pthread_attr_init(&new;_attr) != 0)
   540 {
   541   printf("Cannot initialize attribute object
   542 ");
   543   return -1; /* or exit */
   544 }
   545 rc = pthread_attr_getscope(new_attr, &scope;);
   546 if( rc != 0) {
   547   printf("pthread_attr_getscope failed");
   548   return -1;
   549 }
   550 switch(scope) {
   551  case SYSTEMSCOPE:
   552        printf("scope: System 
   553  ");
   554        break;
   555  case PROCESSSCOPE:
   556        printf("scope: Process 
   557  ");
   558        break;
   559 }
   560 /* Create thread */
   561 /* Destroy attribute */
   562 
   563 @endcode
   564 @code
   565 /* ***************************************************** */
   566 /* Example for pthread_attr_getstacksize                 */
   567 /* ***************************************************** */
   568 pthread_attr_t new_attr;
   569 size_t ssize;
   570 int rc;
   571 /* Initialize attribute */
   572 if(pthread_attr_init(&new;_attr) != 0)
   573 {
   574   printf("Cannot initialize attribute object
   575 ");
   576   return -1; /* or exit */
   577 }
   578 /* Get the default stack_size value */
   579 rc = pthread_attr_getstacksize(&new;_attr, &stack;_size); 
   580 if( rc != 0) {
   581   printf("pthread_attr_getstacksize failed");
   582   return -1;
   583 }
   584 printf("ssize = %lu
   585 ", stack_size);
   586 /* Create thread */
   587 /* Destroy attribute */
   588 
   589 @endcode
   590 @code
   591 /* ***************************************************** */
   592 /* Example for pthread_attr_getschedparam               */
   593 /* ***************************************************** */
   594 pthread_attr_t         attr;
   595 int                    rc=0;
   596 struct sched_param     param;
   597 struct sched_param     param2;
   598 rc = pthread_attr_init(&attr;);
   599 if(rc != 0) {
   600   printf("pthread_attr_init failed
   601 ");
   602   return -1;
   603 }
   604 param.sched_priority = 50;
   605 rc = pthread_attr_setschedparam(&attr;, & param);
   606 if(rc != 0) {
   607   printf("pthread_attr_setschedparam failed
   608 ");
   609   return -1;
   610 }
   611 rc = pthread_attr_getschedparam(&attr;, & param2);
   612 if(rc != 0) {
   613   printf("pthread_attr_getschedparam failed
   614 ");
   615   return -1;
   616 }
   617 /* priority will be stored in param2.sched_priority */
   618 /* Create thread */
   619 /* Destroy attribute */
   620 
   621 @endcode
   622 @code
   623 /* ***************************************************** */
   624 /* Example for pthread_attr_setdetachstate               */
   625 /* ***************************************************** */
   626 pthread_attr_t new_attr;
   627 int detach_state;
   628 /* Initialize attribute */
   629 if(pthread_attr_init(&new;_attr) != 0)
   630 {
   631   perror("Cannot initialize attribute object
   632 ");
   633   return -1;
   634 }
   635 /* Set the attribute object to PTHREAD_CREATE_JOINABLE. */
   636 if(pthread_attr_setdetachstate(&new;_attr, PTHREAD_CREATE_JOINABLE) != 0)
   637 {
   638   perror("Error in pthread_attr_setdetachstate()
   639 ");
   640   return -1;
   641 }
   642 /* Create thread */
   643 /* Destroy attribute */
   644 
   645 @endcode
   646 @code
   647 /* ***************************************************** */
   648 /* Example for pthread_attr_setschedparam               */
   649 /* ***************************************************** */
   650 pthread_attr_t         attr;
   651 int                    rc=0;
   652 struct sched_param     param;
   653 rc = pthread_attr_init(&attr;);
   654 if(rc != 0) {
   655   printf("pthread_attr_init failed
   656 ");
   657   return -1;
   658 }
   659 param.sched_priority = 50;
   660 rc = pthread_attr_setschedparam(&attr;, & param);
   661 if(rc != 0) {
   662   printf("pthread_attr_setschedparam failed
   663 ");
   664   return -1;
   665 }
   666 /* Create thread */
   667 /* Destroy attribute */
   668 
   669 @endcode
   670 @code
   671 /* ***************************************************** */
   672 /* Example for pthread_attr_setschedpolicy               */
   673 /* ***************************************************** */
   674 pthread_attr_t attr;
   675 int rc;
   676 int policy = SCHED_RR;
   677 if(pthread_attr_init(&attr;) != 0) {
   678   printf("Error on pthread_attr_init()
   679 ");
   680   return -1;
   681 }
   682  
   683 if((rc=pthread_attr_setschedpolicy(&attr;,policy)) != 0) {
   684       printf("Error on pthread_attr_setschedpolicy()	 rc=%d
   685 ", rc);
   686       return -1;
   687 }
   688 /* Create thread */
   689 /* Destroy attribute */
   690 
   691 @endcode
   692 @code
   693 /* ***************************************************** */
   694 /* Example for pthread_attr_setstacksize                 */
   695 /* ***************************************************** */
   696 pthread_attr_t attr;
   697 int rc;
   698 int policy = SCHED_RR;
   699 if(pthread_attr_init(&attr;) != 0) {
   700   printf("Error on pthread_attr_init()
   701 ");
   702   return -1;
   703 }
   704  
   705 if((rc=pthread_attr_setstacksize(&attr;,8192)) != 0) {
   706       printf("Error on pthread_attr_setstacksize()	 rc=%d
   707 ", rc);
   708       return -1;
   709 }
   710 /* Create thread */
   711 /* Destroy attribute */
   712 
   713 @endcode
   714 @code
   715 /* ***************************************************** */
   716 /* Example for pthread_attr_setscope                     */
   717 /* ***************************************************** */
   718 pthread_attr_t attr;
   719 int rc;
   720 /* Initialize attr */
   721 rc = pthread_attr_init(&attr;);
   722 if( rc != 0) {
   723   perror("pthread_attr_init failed");
   724   return -1;
   725 }
   726 rc = pthread_attr_setscope(&attr;, PTHREAD_SCOPE_SYSTEM); 
   727 if (rc != 0 ) {
   728   perror("PTHREAD_SCOPE_SYSTEM is not supported");
   729   return -1;
   730 }
   731 /* Create thread */
   732 /* Destroy attribute */
   733 
   734 @endcode
   735 @see pthread_create()
   736 
   737 
   738  
   739 
   740 @publishedAll
   741 @externallyDefinedApi
   742 */
   743 
   744 /** @fn  pthread_attr_destroy(pthread_attr_t *attrib)
   745 @param attrib
   746 Refer  pthread_attr_init() for the documentation
   747 @see pthread_create()
   748 
   749 
   750  
   751 
   752 @publishedAll
   753 @externallyDefinedApi
   754 */
   755 
   756 /** @fn  pthread_attr_getdetachstate(const pthread_attr_t *attrib, int *detState)
   757 @param attrib
   758 @param detState
   759 Refer  pthread_attr_init() for the documentation
   760 @see pthread_create()
   761 
   762 
   763  
   764 
   765 @publishedAll
   766 @externallyDefinedApi
   767 */
   768 
   769 /** @fn  pthread_attr_setdetachstate(pthread_attr_t *attrib, int detState)
   770 @param attrib
   771 @param detState
   772 Refer  pthread_attr_init() for the documentation
   773 @see pthread_create()
   774 
   775 
   776  
   777 
   778 @publishedAll
   779 @externallyDefinedApi
   780 */               
   781                           
   782 /** @fn  pthread_attr_getstacksize(const pthread_attr_t *attrib, size_t *stkSize)
   783 @param attrib
   784 @param stkSize
   785 Refer  pthread_attr_init() for the documentation
   786 @see pthread_create()
   787 
   788 
   789  
   790 
   791 @publishedAll
   792 @externallyDefinedApi
   793 */
   794 
   795 /** @fn  pthread_attr_setstacksize(pthread_attr_t *attrib, size_t stkSize)
   796 @param attrib
   797 @param stkSize
   798 Refer  pthread_attr_init() for the documentation
   799 @see pthread_create()
   800 
   801 
   802  
   803 
   804 @publishedAll
   805 @externallyDefinedApi
   806 */                                                                              
   807 
   808 /** @fn  pthread_once(pthread_once_t *once_control, thread_init_routine init_routine)
   809 @param once_control
   810 @param init_routine
   811 @return   If successful, the pthread_once function will return zero.
   812 Otherwise an error number will be returned to
   813 indicate the error.
   814 
   815   The first call to pthread_once by any thread in a process, with a given once_control ,
   816 will call the init_routine with no arguments.
   817 Subsequent calls to pthread_once with the same once_control will not call the init_routine .
   818 On return from pthread_once ,
   819 it is guaranteed that init_routine has completed.
   820 The once_control parameter is used to determine whether the associated initialization
   821 routine has been called.
   822 
   823  The constant PTHREAD_ONCE_INIT is defined by header \#include \<pthread.h\> .
   824 
   825  The behavior of pthread_once is undefined if once_control has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT .
   826 
   827 Examples:
   828 @code
   829 /* The init function that pthread_once calls */
   830 void an_init_func_1_1()
   831 {
   832 printf (" Initialized ..
   833 ");
   834 }
   835 int XYZ()
   836 {
   837  pthread_once_t once_control = PTHREAD_ONCE_INIT;
   838  /* Call pthread_once, passing it the once_control */
   839  pthread_once(&once;_control, an_init_func_1_1);
   840  /* Call pthread_once again. The init function should not be
   841   * called. */
   842  pthread_once(&once;_control, an_init_func_1_1);
   843 }
   844 
   845 @endcode
   846  
   847 
   848 @publishedAll
   849 @externallyDefinedApi
   850 */
   851 
   852 /** @fn  pthread_mutexattr_init(pthread_mutexattr_t *attr)
   853 @param attr
   854 Note: This description also covers the following functions -
   855  pthread_mutexattr_destroy()  pthread_mutexattr_settype()  pthread_mutexattr_gettype()  pthread_mutexattr_getpshared()  pthread_mutexattr_setpshared() 
   856 
   857 @return   If successful, these functions return 0.
   858 Otherwise, an error number is returned to indicate the error.
   859 
   860   Mutex attributes are used to specify parameters to pthread_mutex_init .
   861 One attribute object can be used in multiple calls to pthread_mutex_init ,
   862 with or without modifications between calls.
   863 
   864  The pthread_mutexattr_init function initializes attr with all the default mutex attributes.
   865 
   866  The pthread_mutexattr_destroy function destroys attr .
   867 
   868  The pthread_mutexattr_set* functions set the attribute that corresponds to each function name.
   869 
   870  The pthread_mutexattr_get* functions copy the value of the attribute that corresponds to each function name
   871 to the location pointed to by the second function parameter.
   872 
   873 Examples:
   874 @code
   875 pthread_mutexattr_t mta;
   876  int rc;
   877  /* Initialize a mutex attributes object */
   878  if((rc=pthread_mutexattr_init(&mta;)) != 0)
   879  {
   880   fprintf(stderr,"Cannot initialize mutex attributes object
   881 ");
   882   return -1;
   883  }
   884  /* Destroy the mutex attributes object */
   885  if(pthread_mutexattr_destroy(&mta;) != 0)
   886  {
   887   fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
   888 ", rc);
   889   return -1;
   890  }
   891 
   892 @endcode
   893 @code
   894  pthread_mutexattr_t mta;
   895  int pshared;
   896  /* Initialize a mutex attributes object */
   897  if(pthread_mutexattr_init(&mta;) != 0)
   898  {
   899   perror("Error at pthread_mutexattr_init()
   900 ");
   901   return -1;
   902  }
   903   /* The default 'pshared' attribute is PTHREAD_PROCESS_PRIVATE  */
   904  if(pthread_mutexattr_getpshared(&mta;, &pshared;) != 0)
   905  {
   906   fprintf(stderr,"Error obtaining the attribute process-shared
   907 ");
   908   return -1;
   909  }
   910 if (pshared != PTHREAD_PROCESS_PRIVATE)
   911      printf (" pshared is NOT PTHREAD_PROCESS_PRIVATE
   912 ");
   913 
   914 @endcode
   915 @code
   916  pthread_mutexattr_t mta;
   917  int type;
   918  /* Initialize a mutex attributes object */
   919  if(pthread_mutexattr_init(&mta;) != 0)
   920  {
   921   perror("Error at pthread_mutexattr_init()
   922 ");
   923   return -1;
   924  }
   925   /* The default 'type' attribute  is PTHREAD_MUTEX_DEFAULT  */
   926  if(pthread_mutexattr_gettype(&mta;, &type;) != 0)
   927  {
   928   fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'
   929 ");
   930   return -1;
   931  }
   932  if(type != PTHREAD_MUTEX_DEFAULT)
   933  {
   934   printf("FAILED: Incorrect default mutexattr 'type' value: %d
   935 ", type);
   936   return -1;
   937  }
   938 
   939 @endcode
   940 @code
   941 pthread_mutexattr_t mta;
   942  int rc;
   943  /* Initialize a mutex attributes object */
   944  if((rc=pthread_mutexattr_init(&mta;)) != 0)
   945  {
   946   fprintf(stderr,"Cannot initialize mutex attributes object
   947 ");
   948   return -1;
   949  }
   950  /* Destroy the mutex attributes object */
   951  if(pthread_mutexattr_destroy(&mta;) != 0)
   952  {
   953   fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
   954 ", rc);
   955   return -1;
   956  }
   957 
   958 @endcode
   959 @code
   960 pthread_mutexattr_t mta;
   961  int ret;
   962  /* Initialize a mutex attributes object */
   963  if(pthread_mutexattr_init(&mta;) != 0)
   964  {
   965   perror("Error at pthread_mutexattr_init()
   966 ");
   967   return -1;
   968  }
   969  /* Set the 'pshared' attribute to PTHREAD_PROCESS_PRIVATE */
   970  if((ret=pthread_mutexattr_setpshared(&mta;, PTHREAD_PROCESS_PRIVATE)) != 0)
   971  {
   972   printf("FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_PRIVATE. Error: %d
   973 ", ret);
   974   return -1;
   975  }
   976 
   977 @endcode
   978 @code
   979  pthread_mutexattr_t mta;
   980  int type;
   981  /* Initialize a mutex attributes object */
   982  if(pthread_mutexattr_init(&mta;) != 0)
   983  {
   984   perror("Error at pthread_mutexattr_init()
   985 ");
   986   return -1;
   987  }
   988  if(pthread_mutexattr_gettype(&mta;, &type;) != 0)
   989  {
   990   printf("Error getting the attribute 'type'
   991 ");
   992   return -1;
   993  }
   994  if(type != PTHREAD_MUTEX_DEFAULT)
   995  {
   996   printf("FAILED: Default value of the 'type' attribute is not PTHREAD_MUTEX_DEFAULT 
   997 ");
   998   return -1; 
   999  }
  1000  if(pthread_mutexattr_settype(&mta;, PTHREAD_MUTEX_NORMAL) != 0)
  1001  {
  1002   printf("FAILED: Error setting the attribute 'type'
  1003 ");
  1004   return -1;
  1005  }
  1006 
  1007 @endcode
  1008 @see pthread_mutex_init()
  1009 
  1010 
  1011  
  1012 
  1013 @publishedAll
  1014 @externallyDefinedApi
  1015 */
  1016 
  1017 /** @fn  pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
  1018 @param attr
  1019 Refer  pthread_mutexattr_init() for the documentation
  1020 @see pthread_mutex_init()
  1021 
  1022 
  1023  
  1024 
  1025 @publishedAll
  1026 @externallyDefinedApi
  1027 */
  1028 
  1029 /** @fn  pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
  1030 @param attr
  1031 @param pshared
  1032 Refer  pthread_mutexattr_init() for the documentation
  1033 @see pthread_mutex_init()
  1034 
  1035 
  1036  
  1037 
  1038 @publishedAll
  1039 @externallyDefinedApi
  1040 */
  1041 
  1042 /** @fn  pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
  1043 @param attr
  1044 @param type
  1045 Refer  pthread_mutexattr_init() for the documentation
  1046 @see pthread_mutex_init()
  1047 
  1048 
  1049  
  1050 
  1051 @publishedAll
  1052 @externallyDefinedApi
  1053 */
  1054 
  1055 /** @fn  pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
  1056 @param attr
  1057 @param type # use integer valuses between 1 and 10
  1058 Refer  pthread_mutexattr_init() for the documentation
  1059 @see pthread_mutex_init()
  1060 
  1061 
  1062  
  1063 
  1064 @publishedAll
  1065 @externallyDefinedApi
  1066 */
  1067 
  1068 /** @fn  pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
  1069 @param mutex
  1070 @param attr
  1071 @return   If successful, pthread_mutex_init will return zero and put the new mutex id into mutex ,
  1072 otherwise an error number will be returned to indicate the error.
  1073 
  1074   The pthread_mutex_init function creates a new mutex, with attributes specified with attr .
  1075 If attr is NULL the default attributes are used.
  1076 
  1077 Examples:
  1078 @code
  1079 pthread_mutex_t  mutex;
  1080 int XYZ()
  1081 {
  1082  int rc;
  1083  /* Initialize a mutex object with the default mutex attributes */
  1084  if((rc=pthread_mutex_init(&mutex;,NULL)) != 0)
  1085         {
  1086         fprintf(stderr,"Error at pthread_mutex_init(), rc=%d0,rc);
  1087         return -1;
  1088         }
  1089 }
  1090 
  1091 @endcode
  1092 @see pthread_mutex_destroy()
  1093 @see pthread_mutex_lock()
  1094 @see pthread_mutex_trylock()
  1095 @see pthread_mutex_unlock()
  1096 
  1097 
  1098  
  1099 
  1100 @publishedAll
  1101 @externallyDefinedApi
  1102 */
  1103 
  1104 /** @fn  pthread_mutex_destroy(pthread_mutex_t *mutex)
  1105 @param mutex
  1106 @return   If successful, pthread_mutex_destroy will return zero, otherwise an error number will be returned to
  1107 indicate the error.
  1108 
  1109   The pthread_mutex_destroy function frees the resources allocated for mutex .
  1110 
  1111 Examples:
  1112 @code
  1113  pthread_mutexattr_t mta;
  1114  int rc;
  1115  /* Initialize a mutex attributes object */
  1116  if((rc=pthread_mutexattr_init(&mta;)) != 0) {
  1117   fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d
  1118 ",rc);
  1119   return -1;
  1120  }
  1121  /* Destroy the mutex attributes object */
  1122  if((rc=pthread_mutexattr_destroy(&mta;)) != 0) {
  1123   fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
  1124 ",rc);
  1125   return -1;
  1126  }
  1127 
  1128 @endcode
  1129 @see pthread_mutex_init()
  1130 @see pthread_mutex_lock()
  1131 @see pthread_mutex_trylock()
  1132 @see pthread_mutex_unlock()
  1133 
  1134 
  1135  
  1136 
  1137 @publishedAll
  1138 @externallyDefinedApi
  1139 */
  1140 
  1141 /** @fn  pthread_mutex_lock(pthread_mutex_t *mutex)
  1142 @param mutex
  1143 @return   If successful, pthread_mutex_lock will return zero, otherwise an error number will be returned to
  1144 indicate the error.
  1145 
  1146   The pthread_mutex_lock function locks mutex .
  1147 If the mutex is already locked, the calling thread will block until the
  1148 mutex becomes available.
  1149 
  1150 Examples:
  1151 @code
  1152 pthread_mutex_t  mutex;
  1153 int XYZ()
  1154 {
  1155  int rc;
  1156  /* Initialize a mutex object with the default mutex attributes */
  1157  if((rc=pthread_mutex_init(&mutex;,NULL)) != 0) {
  1158   fprintf(stderr,"Error at pthread_mutex_init(), rc=%d
  1159 ",rc);
  1160   return -1;
  1161  }
  1162  /* Lock the mutex using pthread_mutex_lock() */
  1163  if((rc=pthread_mutex_lock(&mutex;)) == 0) {
  1164   printf(" lock is successful
  1165 ");
  1166  }
  1167 }
  1168 
  1169 @endcode
  1170 @see pthread_mutex_destroy()
  1171 @see pthread_mutex_init()
  1172 @see pthread_mutex_trylock()
  1173 @see pthread_mutex_unlock()
  1174 
  1175 
  1176  
  1177 
  1178 @publishedAll
  1179 @externallyDefinedApi
  1180 */
  1181 
  1182 /** @fn  pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
  1183 @param mutex
  1184 @param abstime
  1185 @return   If successful, pthread_mutex_timedlock will return zero, otherwise an error number will be returned to
  1186 indicate the error.
  1187 
  1188   The pthread_mutex_timedlock function will lock mutex .
  1189 If it is already locked the calling thread will block until
  1190 the mutex becomes available or
  1191 the timeout,
  1192 specified by abstime,
  1193 expires.
  1194 The time of the timeout is an absolute time and
  1195 is not relative to the current time.
  1196 
  1197 Examples:
  1198 @code
  1199 #include <sys/time.h>
  1200 #define TIMEOUT 3    
  1201 /* 3 seconds of timeout time for  pthread_mutex_timedlock(). */
  1202 struct timespec timeout;
  1203 struct timeval currsec1;
  1204 int rc;
  1205 pthread_mutex_t  mutex;
  1206 
  1207 
  1208 /* Get the current time before the mutex locked. */
  1209 gettimeofday(&currsec1;, NULL);
  1210 /* Absolute time, not relative. */
  1211 timeout.tv_sec = currsec1.tv_sec + TIMEOUT;
  1212 timeout.tv_nsec = currsec1.tv_usec * 1000;
  1213 printf("Timed mutex lock will block for %d seconds starting from: %ld.%06ld
  1214 ", TIMEOUT, (long)currsec1.tv_sec, (long)currsec1.tv_usec);
  1215 rc = pthread_mutex_timedlock(&mutex;, &timeout;);
  1216 if(rc != 0) {
  1217   if (rc == ETIMEDOUT) {
  1218    fprintf(stderr,"Thread stops waiting when time is out
  1219 ");
  1220   }
  1221   else {
  1222    fprintf(stderr,"pthread_mutex_timedwait return %d
  1223 ", rc);
  1224   }
  1225 }
  1226 fprintf(stderr,"Thread wakened up
  1227 ");
  1228 
  1229 @endcode
  1230 @see pthread_mutex_destroy()
  1231 @see pthread_mutex_init()
  1232 @see pthread_mutex_lock()
  1233 @see pthread_mutex_trylock()
  1234 @see pthread_mutex_unlock()
  1235 
  1236 
  1237  
  1238 
  1239 @publishedAll
  1240 @externallyDefinedApi
  1241 */
  1242 
  1243 /** @fn  pthread_mutex_trylock(pthread_mutex_t *mutex)
  1244 @param mutex
  1245 @return   If successful, pthread_mutex_trylock will return zero, otherwise an error number will be returned to
  1246 indicate the error.
  1247 
  1248   The pthread_mutex_trylock function locks mutex .
  1249 If the mutex is already locked, pthread_mutex_trylock will not block waiting for the mutex, but will return an error condition.
  1250 
  1251 Examples:
  1252 @code
  1253 int rc;
  1254 pthread_mutex_t  mutex;
  1255 rc = pthread_mutex_trylock(&mutex;);
  1256 switch (rc)
  1257 {
  1258    case 0:
  1259        printf ("Locked successfully
  1260 ");
  1261        break;
  1262    case EAGAIN:
  1263        printf ("could not lock, try later.....
  1264 ");
  1265        break;
  1266 }
  1267 
  1268 @endcode
  1269 @see pthread_mutex_destroy()
  1270 @see pthread_mutex_init()
  1271 @see pthread_mutex_lock()
  1272 @see pthread_mutex_unlock()
  1273 
  1274 
  1275  
  1276 
  1277 @publishedAll
  1278 @externallyDefinedApi
  1279 */
  1280 
  1281 /** @fn  pthread_mutex_unlock(pthread_mutex_t *mutex)
  1282 @param mutex
  1283 @return   If successful, pthread_mutex_unlock will return zero, otherwise an error number will be returned to
  1284 indicate the error.
  1285 
  1286   If the current thread holds the lock on mutex ,
  1287 then the pthread_mutex_unlock function unlocks mutex .
  1288 
  1289 Examples:
  1290 @code
  1291 static pthread_mutex_t    mutex = PTHREAD_MUTEX_INITIALIZER;
  1292 int XYZ()
  1293 {
  1294    int  rc;
  1295  /* Get the mutex using pthread_mutex_lock() */
  1296  if((rc=pthread_mutex_lock(&mutex;)) != 0) {
  1297   fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d
  1298 ",rc);
  1299   return -1;
  1300  }
  1301  /* Release the mutex using pthread_mutex_unlock() */
  1302  if((rc=pthread_mutex_unlock(&mutex;)) != 0) {
  1303   printf("unlock failed 
  1304 ");
  1305   return -1;
  1306  }  
  1307 
  1308 @endcode
  1309 @see pthread_mutex_destroy()
  1310 @see pthread_mutex_init()
  1311 @see pthread_mutex_lock()
  1312 @see pthread_mutex_trylock()
  1313 
  1314 
  1315  
  1316 
  1317 @publishedAll
  1318 @externallyDefinedApi
  1319 */
  1320 
  1321 /** @fn  pthread_condattr_init(pthread_condattr_t *)
  1322 
  1323 Note: This description also covers the following functions -
  1324  pthread_condattr_destroy() 
  1325 
  1326 @return   If successful, these functions return 0.
  1327 Otherwise, an error number is returned to indicate the error.
  1328 
  1329   Condition attribute objects are used to specify parameters to pthread_cond_init .
  1330 Current implementation of conditional variables does not support any
  1331 attributes, so these functions are not very useful.
  1332 
  1333  The pthread_condattr_init function initializes a condition attribute object with the default
  1334 attributes.(As of now None)
  1335 
  1336  The pthread_condattr_destroy function destroys a condition attribute object.
  1337 
  1338 Examples:
  1339 @code
  1340  pthread_condattr_t condattr;
  1341  int rc;
  1342  /* Initialize a condition variable attributes object */
  1343  if((rc=pthread_condattr_init(&condattr;)) != 0)
  1344  {
  1345   fprintf(stderr,"Cannot initialize condition variable attributes object
  1346 ");
  1347   return -1;
  1348  }
  1349  /* Destroy the condition variable attributes object */
  1350  if(pthread_condattr_destroy(&condattr;) != 0)
  1351  {
  1352   fprintf(stderr,"Error at pthread_condattr_destroy(), rc=%d
  1353 ", rc);
  1354   return -1;
  1355  }
  1356 
  1357 @endcode
  1358 @see pthread_cond_init()
  1359 
  1360 
  1361  
  1362 
  1363 @publishedAll
  1364 @externallyDefinedApi
  1365 */
  1366 
  1367 /** @fn  pthread_condattr_destroy(pthread_condattr_t *)
  1368 
  1369 Refer  pthread_condattr_init() for the documentation
  1370 @see pthread_cond_init()
  1371 
  1372 
  1373  
  1374 
  1375 @publishedAll
  1376 @externallyDefinedApi
  1377 */
  1378 
  1379 /** @fn  pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *)
  1380 @param cond
  1381 @param # represents the parameter attr
  1382 @return   If successful, the pthread_cond_init function will return zero and put the new condition variable id into cond ,
  1383 otherwise an error number will be returned to indicate the error.
  1384 
  1385   The pthread_cond_init function creates a new condition variable referenced 
  1386 by cond with attributes referenced by attr. If attr is NULL, the default condition variable attributes will be used. 
  1387 Upon successful initialization, the state of the condition variable will be initialized.
  1388 
  1389 Examples:
  1390 @code
  1391 int rc;
  1392 struct testdata
  1393 {
  1394  pthread_mutex_t mutex;
  1395  pthread_cond_t  cond;
  1396 };
  1397 static struct testdata td;
  1398 int function1()
  1399 {
  1400  /* Initialize a condition variable object */
  1401  if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1402   fprintf(stderr,"Fail to initialize cond
  1403 ");
  1404   return -1;
  1405  }
  1406  /* ... Use it for wait, signal, broadcast */
  1407  /* Destroy the condition variable object */
  1408  if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1409  {
  1410    fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1411 ",rc);
  1412    return -1;
  1413  }
  1414 }
  1415 
  1416 @endcode
  1417 @see pthread_cond_broadcast()
  1418 @see pthread_cond_destroy()
  1419 @see pthread_cond_signal()
  1420 @see pthread_cond_timedwait()
  1421 @see pthread_cond_wait()
  1422 
  1423 
  1424  
  1425 
  1426 @publishedAll
  1427 @externallyDefinedApi
  1428 */
  1429 
  1430 /** @fn  pthread_cond_destroy(pthread_cond_t *cond)
  1431 @param cond
  1432 @return   If successful, the pthread_cond_destroy function will return zero, otherwise an error number will be returned
  1433 to indicate the error.
  1434 
  1435   The pthread_cond_destroy function frees the resources allocated by the condition variable cond .
  1436 
  1437 Examples:
  1438 @code
  1439 int rc;
  1440 struct testdata
  1441 {
  1442  pthread_mutex_t mutex;
  1443  pthread_cond_t  cond;
  1444 };
  1445 static struct testdata td;
  1446 int function1()
  1447 {
  1448  /* Initialize a condition variable object */
  1449  if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1450   fprintf(stderr,"Fail to initialize cond
  1451 ");
  1452   return -1;
  1453  }
  1454  /* ... Use it for wait, signal, broadcast */
  1455  /* Destroy the condition variable object */
  1456  if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1457  {
  1458    fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1459 ",rc);
  1460    return -1;
  1461  }
  1462 }
  1463 
  1464 @endcode
  1465 @see pthread_cond_broadcast()
  1466 @see pthread_cond_init()
  1467 @see pthread_cond_signal()
  1468 @see pthread_cond_timedwait()
  1469 @see pthread_cond_wait()
  1470 
  1471 
  1472  
  1473 
  1474 @publishedAll
  1475 @externallyDefinedApi
  1476 */
  1477 
  1478 /** @fn  pthread_cond_destroy(pthread_cond_t *cond)
  1479 @param cond
  1480 @return   If successful, the pthread_cond_destroy function will return zero, otherwise an error number will be returned
  1481 to indicate the error.
  1482 
  1483   The pthread_cond_destroy function frees the resources allocated by the condition variable cond .
  1484 
  1485 Examples:
  1486 @code
  1487 int rc;
  1488 struct testdata
  1489 {
  1490  pthread_mutex_t mutex;
  1491  pthread_cond_t  cond;
  1492 };
  1493 static struct testdata td;
  1494 int function1()
  1495 {
  1496  /* Initialize a condition variable object */
  1497  if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1498   fprintf(stderr,"Fail to initialize cond
  1499 ");
  1500   return -1;
  1501  }
  1502  /* ... Use it for wait, signal, broadcast */
  1503  /* Destroy the condition variable object */
  1504  if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1505  {
  1506    fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1507 ",rc);
  1508    return -1;
  1509  }
  1510 }
  1511 
  1512 @endcode
  1513 @see pthread_cond_broadcast()
  1514 @see pthread_cond_init()
  1515 @see pthread_cond_signal()
  1516 @see pthread_cond_timedwait()
  1517 @see pthread_cond_wait()
  1518 
  1519 
  1520  
  1521 
  1522 @publishedAll
  1523 @externallyDefinedApi
  1524 */
  1525 
  1526 /** @fn  pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
  1527 @param cond
  1528 @param mutex
  1529 @return   If successful, the pthread_cond_wait function will return zero.
  1530 Otherwise an error number will be returned to
  1531 indicate the error.
  1532 
  1533   The pthread_cond_wait function atomically blocks the current thread waiting on the condition
  1534 variable specified by cond ,
  1535 and unblocks the mutex specified by mutex .
  1536 The waiting thread unblocks only after another thread calls pthread_cond_signal ,
  1537 or pthread_cond_broadcast with the same condition variable, and the current thread reacquires the lock
  1538 on mutex .
  1539 
  1540 Examples:
  1541 @code
  1542 struct testdata
  1543 {
  1544  pthread_mutex_t mutex;
  1545  pthread_cond_t  cond;
  1546 };
  1547 static struct testdata td;
  1548 int rc;
  1549 /* mutex and conditional variable must be initialized */
  1550 if (pthread_mutex_lock(&td.mutex;) != 0) {
  1551   fprintf(stderr,"Thread failed to acquire mutex
  1552 ");
  1553   return -1;
  1554  }
  1555 fprintf(stderr,"Thread started
  1556 ");
  1557 fprintf(stderr,"Thread is waiting for the cond
  1558 ");
  1559 rc = pthread_cond_wait(&td.cond;, &td.mutex;);
  1560 if (rc != 0) {
  1561   fprintf(stderr,"pthread_cond_wait return %d
  1562 ", rc);
  1563   return -1;
  1564 }
  1565 fprintf(stderr,"Thread wakened
  1566 ");
  1567 pthread_mutex_unlock(&td.mutex;);
  1568 
  1569 @endcode
  1570 @see pthread_cond_broadcast()
  1571 @see pthread_cond_destroy()
  1572 @see pthread_cond_init()
  1573 @see pthread_cond_signal()
  1574 @see pthread_cond_timedwait()
  1575 
  1576 
  1577  
  1578 
  1579 @publishedAll
  1580 @externallyDefinedApi
  1581 */
  1582 
  1583 /** @fn  pthread_cond_signal(pthread_cond_t *cond)
  1584 @param cond
  1585 @return   If successful, the pthread_cond_signal function will return zero, otherwise an error number will be returned
  1586 to indicate the error.
  1587 
  1588   The pthread_cond_signal function unblocks one thread waiting for the condition variable cond .
  1589 
  1590 Examples:
  1591 @code
  1592  int rc;
  1593 struct testdata
  1594 {
  1595  pthread_mutex_t mutex;
  1596  pthread_cond_t  cond;
  1597 };
  1598 static struct testdata td;
  1599 int function1()
  1600 {
  1601  if (pthread_mutex_init(&td.mutex;, NULL) != 0) {
  1602   fprintf(stderr,"Fail to initialize mutex
  1603 ");
  1604   return -1;
  1605  }
  1606  if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1607   fprintf(stderr,"Fail to initialize cond
  1608 ");
  1609   return -1;
  1610  }
  1611  /* ....... other thread wait for signal */
  1612  /* Acquire the mutex to make sure that all waiters are currently 
  1613     blocked on pthread_cond_wait */
  1614  if (pthread_mutex_lock(&td.mutex;) != 0) {
  1615   fprintf(stderr,"Main: Fail to acquire mutex
  1616 ");
  1617   return -1;
  1618  }
  1619  if (pthread_mutex_unlock(&td.mutex;) != 0) {
  1620   fprintf(stderr,"Main: Fail to release mutex
  1621 ");
  1622   return -1;
  1623  }
  1624  /* signal the condition to wake up all waiters */
  1625  fprintf(stderr," signal the condition
  1626 ");
  1627  rc = pthread_cond_signal(&td.cond;);
  1628  if (rc != 0) {
  1629   fprintf(stderr," failed to signal the condition
  1630 ");
  1631   return -1;
  1632  }
  1633 }
  1634 
  1635 @endcode
  1636 @see pthread_cond_broadcast()
  1637 @see pthread_cond_destroy()
  1638 @see pthread_cond_init()
  1639 @see pthread_cond_timedwait()
  1640 @see pthread_cond_wait()
  1641 
  1642 
  1643  
  1644 
  1645 @publishedAll
  1646 @externallyDefinedApi
  1647 */
  1648 
  1649 /** @fn  pthread_cond_broadcast(pthread_cond_t *cond)
  1650 @param cond
  1651 @return   If successful, the pthread_cond_broadcast function will return zero, otherwise an error number will be returned
  1652 to indicate the error.
  1653 
  1654   The pthread_cond_broadcast function unblocks all threads waiting for the condition variable cond .
  1655 
  1656 Examples:
  1657 @code
  1658  int rc;
  1659 struct testdata
  1660 {
  1661  pthread_mutex_t mutex;
  1662  pthread_cond_t  cond;
  1663 };
  1664 static struct testdata td;
  1665  if (pthread_mutex_init(&td.mutex;, NULL) != 0) {
  1666   fprintf(stderr,"Fail to initialize mutex
  1667 ");
  1668   return -1;
  1669  }
  1670  if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1671   fprintf(stderr,"Fail to initialize cond
  1672 ");
  1673   return -1;
  1674  }
  1675 /* ....... other thread wait for signal */
  1676  /* Acquire the mutex to make sure that all waiters are currently 
  1677     blocked on pthread_cond_wait */
  1678  if (pthread_mutex_lock(&td.mutex;) != 0) {
  1679   fprintf(stderr,"Main: Fail to acquire mutex
  1680 ");
  1681   return -1;
  1682  }
  1683  if (pthread_mutex_unlock(&td.mutex;) != 0) {
  1684   fprintf(stderr,"Main: Fail to release mutex
  1685 ");
  1686   return -1;
  1687  }
  1688  /* signal the condition to wake up all waiters */
  1689  fprintf(stderr," signal the condition0);
  1690  rc = pthread_cond_broadcast(&td.cond;);
  1691  if (rc != 0) {
  1692   fprintf(stderr," failed to signal the condition
  1693 ");
  1694   return -1;
  1695  }
  1696 
  1697 @endcode
  1698 @see pthread_cond_destroy()
  1699 @see pthread_cond_init()
  1700 @see pthread_cond_signal()
  1701 @see pthread_cond_timedwait()
  1702 @see pthread_cond_wait()
  1703 
  1704 
  1705  
  1706 
  1707 @publishedAll
  1708 @externallyDefinedApi
  1709 */
  1710 
  1711 /** @fn  pthread_key_create(pthread_key_t *key, destructor_routine dest)
  1712 @param key
  1713 @param dest
  1714 @return   If successful, the pthread_key_create function will store the newly created key value at the location specified by key and returns zero.
  1715 Otherwise an error number will be returned to indicate
  1716 the error.
  1717 
  1718   The pthread_key_create function creates a thread-specific data key visible to all threads in the
  1719 process.
  1720 Key values provided by pthread_key_create are opaque objects used to locate thread-specific data.
  1721 Although the same
  1722 key value may be used by different threads, the values bound to the key
  1723 by pthread_setspecific are maintained on a per-thread basis and persist for the life of the calling
  1724 thread.
  1725 
  1726  Upon key creation, the value NULL is associated with the new key in all
  1727 active threads.
  1728 Upon thread creation, the value NULL is associated with all
  1729 defined keys in the new thread.
  1730 
  1731  An optional destructor function dest may be associated with each key value.
  1732 At
  1733 thread exit, if a key value has a non-NULL destructor pointer, and the
  1734 thread has a non-NULL value associated with the key, the function pointed
  1735 to is called with the current associated value as its sole argument.
  1736 The
  1737 order of destructor calls is unspecified if more than one destructor exists
  1738 for a thread when it exits.
  1739 
  1740  If, after all the destructors have been called for all non-NULL values
  1741 with associated destructors, there are still some non-NULL values with
  1742 associated destructors, then the process is repeated.
  1743 If, after at least
  1744 [PTHREAD_DESTRUCTOR_ITERATIONS] iterations of destructor calls for
  1745 outstanding non-NULL values, there are still some non-NULL values with
  1746 associated destructors, the implementation stops calling destructors.
  1747 
  1748 Examples:
  1749 @code
  1750 pthread_key_t keys;
  1751 if(pthread_key_create(&keys;, NULL) != 0)
  1752 {
  1753    printf("Error: pthread_key_create() failed
  1754 ");
  1755    return -1;
  1756 }
  1757 
  1758 @endcode
  1759 @see pthread_getspecific()
  1760 @see pthread_key_delete()
  1761 @see pthread_setspecific()
  1762 
  1763 
  1764  
  1765 
  1766 @publishedAll
  1767 @externallyDefinedApi
  1768 */
  1769 
  1770 /** @fn  pthread_key_delete(pthread_key_t key)
  1771 @param key
  1772 @return   If successful, the pthread_key_delete function will return zero.
  1773 Otherwise an error number will be returned to
  1774 indicate the error.
  1775 
  1776   The pthread_key_delete function deletes a thread-specific data key previously returned by pthread_key_create .
  1777 The thread-specific data values associated with key need not be NULL at the time that pthread_key_delete is called.
  1778 It is the responsibility of the application to free any
  1779 application storage or perform any cleanup actions for data structures
  1780 related to the deleted key or associated thread-specific data in any threads;
  1781 this cleanup can be done either before or after pthread_key_delete is called.
  1782 Any attempt to use key following the call to pthread_key_delete results in undefined behavior.
  1783 
  1784  The pthread_key_delete function is callable from within destructor functions.
  1785 Destructor functions
  1786 are not invoked by pthread_key_delete .
  1787 Any destructor function that may have been associated with key will no longer be called upon thread exit.
  1788 
  1789 Examples:
  1790 @code
  1791 pthread_key_t keys;
  1792 if(pthread_key_create(&keys;, NULL) != 0)
  1793 {
  1794    printf("Error: pthread_key_create() failed
  1795 ");
  1796    return -1;
  1797 }
  1798 if(pthread_key_delete(keys) != 0)
  1799 {
  1800   printf("Error: pthread_key_delete() failed
  1801 ");
  1802   return -1;  
  1803 }
  1804 
  1805 @endcode
  1806 @see pthread_getspecific()
  1807 @see pthread_key_create()
  1808 @see pthread_setspecific()
  1809 
  1810 
  1811  
  1812 
  1813 @publishedAll
  1814 @externallyDefinedApi
  1815 */
  1816 
  1817 /** @fn  pthread_setspecific(pthread_key_t key, const void *value)
  1818 @param key
  1819 @param value
  1820 @return   If successful, the pthread_setspecific function will return zero.
  1821 Otherwise an error number will be returned to
  1822 indicate the error.
  1823 
  1824   The pthread_setspecific function associates a thread-specific value with a key obtained via a previous call to pthread_key_create .
  1825 Different threads can bind different values to the same key.
  1826 These values are
  1827 typically pointers to blocks of dynamically allocated memory that have been
  1828 reserved for use by the calling thread.
  1829 
  1830  The effect of calling pthread_setspecific with a key value not obtained from pthread_key_create or after key has been deleted with pthread_key_delete is undefined.
  1831 
  1832  The pthread_setspecific function may be called from a thread-specific data destructor function,
  1833 however this may result in lost storage or infinite loops.
  1834 
  1835 Examples:
  1836 @code
  1837  pthread_key_t keys;
  1838  void* rc;
  1839 if(pthread_key_create(&keys;, NULL) != 0)
  1840 {
  1841    printf("Error: pthread_key_create() failed
  1842 ");
  1843    return -1;
  1844 } else
  1845 {
  1846    if(pthread_setspecific(keys, (void *)(long)(100)) != 0)
  1847    {
  1848     printf("Error: pthread_setspecific() failed
  1849 ");
  1850     return -1;
  1851    }
  1852 }
  1853 
  1854 @endcode
  1855 @see pthread_getspecific()
  1856 @see pthread_key_create()
  1857 @see pthread_key_delete()
  1858 
  1859 
  1860  
  1861 
  1862 @publishedAll
  1863 @externallyDefinedApi
  1864 */
  1865 
  1866 /** @fn  pthread_getspecific(pthread_key_t key)
  1867 @param key
  1868 @return   The pthread_getspecific function will return the thread-specific data value associated with the given key .
  1869 If no thread-specific data value is associated with key ,
  1870 then the value NULL is returned.
  1871 
  1872   The pthread_getspecific function returns the value currently bound to the specified key on behalf of the calling thread.
  1873 
  1874  The effect of calling pthread_getspecific with a key value not obtained from pthread_key_create or after key has been deleted with pthread_key_delete is undefined.
  1875 
  1876  The pthread_getspecific function may be called from a thread-specific data destructor function.
  1877 
  1878 Examples:
  1879 @code
  1880 pthread_key_t keys;
  1881  void* rc;
  1882 if(pthread_key_create(&keys;, NULL) != 0)
  1883 {
  1884    printf("Error: pthread_key_create() failed0);
  1885    return -1;
  1886 } else
  1887 {
  1888    if(pthread_setspecific(keys, (void *)(long)(100)) != 0)
  1889    {
  1890     printf("Error: pthread_setspecific() failed
  1891 ");
  1892     return -1;
  1893    }
  1894 }
  1895 rc = pthread_getspecific(keys);
  1896 if(rc != (void *)(long)(100))
  1897 {
  1898    printf("getspecific failed 
  1899 ");
  1900    return -1;
  1901 }
  1902 
  1903 @endcode
  1904 @see pthread_key_create()
  1905 @see pthread_key_delete()
  1906 @see pthread_setspecific()
  1907 
  1908 
  1909  
  1910 
  1911 @publishedAll
  1912 @externallyDefinedApi
  1913 */
  1914 
  1915 /** @fn  pthread_attr_getscope(const pthread_attr_t *attrib, int *scope)
  1916 @param attrib
  1917 @param scope
  1918 Refer  pthread_attr_init() for the documentation
  1919 @see pthread_create()
  1920 
  1921 
  1922  
  1923 
  1924 @publishedAll
  1925 @externallyDefinedApi
  1926 */
  1927 
  1928 /** @fn  pthread_attr_setscope(pthread_attr_t *attrib, int conscope)
  1929 @param attrib
  1930 @param conscope
  1931 Refer  pthread_attr_init() for the documentation
  1932 @see pthread_create()
  1933 
  1934 
  1935  
  1936 
  1937 @publishedAll
  1938 @externallyDefinedApi
  1939 */
  1940 
  1941 /** @fn  pthread_attr_setschedpolicy(pthread_attr_t *attrib, int policy)
  1942 @param attrib
  1943 @param policy
  1944 Refer  pthread_attr_init() for the documentation
  1945 @see pthread_create()
  1946 
  1947 
  1948  
  1949 
  1950 @publishedAll
  1951 @externallyDefinedApi
  1952 */
  1953 
  1954 /** @fn  pthread_attr_getschedpolicy(const pthread_attr_t *attrib, int *policy)
  1955 @param attrib
  1956 @param policy
  1957 Refer  pthread_attr_init() for the documentation
  1958 @see pthread_create()
  1959 
  1960 
  1961  
  1962 
  1963 @publishedAll
  1964 @externallyDefinedApi
  1965 */
  1966 
  1967 /** @fn  pthread_attr_getschedparam(const pthread_attr_t *attrib, struct sched_param *param)
  1968 @param attrib
  1969 @param param
  1970 Refer  pthread_attr_init() for the documentation
  1971 @see pthread_create()
  1972 
  1973 
  1974  
  1975 
  1976 @publishedAll
  1977 @externallyDefinedApi
  1978 */
  1979 
  1980 /** @fn  pthread_attr_setschedparam(pthread_attr_t *attrib, const struct sched_param *param)
  1981 @param attrib
  1982 @param param
  1983 Refer  pthread_attr_init() for the documentation
  1984 @see pthread_create()
  1985 
  1986 
  1987  
  1988 
  1989 @publishedAll
  1990 @externallyDefinedApi
  1991 */          
  1992                            
  1993 /** @fn  pthread_getschedparam(pthread_t thr, int *policy, struct sched_param *param)
  1994 @param thr
  1995 @param policy
  1996 @param param
  1997 Refer  pthread_setschedparam() for the documentation
  1998 
  1999 
  2000  
  2001 
  2002 @publishedAll
  2003 @externallyDefinedApi
  2004 */  
  2005                                       
  2006 /** @fn  pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
  2007 @param thread
  2008 @param policy
  2009 @param param
  2010 Note: This description also covers the following functions -
  2011  pthread_getschedparam() 
  2012 
  2013 @return   If successful, these functions return 0.
  2014 Otherwise, an error number is returned to indicate the error.
  2015 
  2016   The pthread_setschedparam and pthread_getschedparam functions set and get the scheduling parameters of individual threads.
  2017 The scheduling policy for a thread will be SCHED_RR (round-robin). ( SCHED_FIFO is not supported)
  2018 The thread priority (accessed via param-\>sched_priority )
  2019 must be at least PTHREAD_MIN_PRIORITY and no more than PTHREAD_MAX_PRIORITY(as returned by sched_get_priority_max() and sched_get_priority_min() APIs) .
  2020 
  2021 Examples:
  2022 @code
  2023 struct sched_param sparam;
  2024 int policy, priority, policy_1;
  2025 int rc;
  2026 policy = SCHED_RR;
  2027 priority = 50;
  2028 sparam.sched_priority = priority;
  2029 rc = pthread_setschedparam(pthread_self(), policy, &sparam;);
  2030 if (rc != 0)
  2031 {
  2032   printf("Error at pthread_setschedparam: rc=%d
  2033 ", rc);
  2034   return -1;
  2035 }
  2036 
  2037 @endcode
  2038 @code
  2039 int e ;
  2040 struct sched_param param;
  2041 pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
  2042 pthread_t thread = pthread_self();
  2043 param.sched_priority = 100;
  2044  
  2045 e = pthread_setschedparam(thread,SCHED_RR, & param);
  2046 if(e != 0)
  2047 {
  2048    printf("setting scheduling policy and priority failed."));
  2049    return -1;
  2050 }
  2051 
  2052 @endcode
  2053 @code
  2054 int e ;
  2055 struct sched_param param;
  2056 pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
  2057 int policy;
  2058 pthread_t thread = pthread_self();
  2059 param.sched_priority = 100;
  2060  
  2061 e = pthread_setschedparam(thread,SCHED_RR, & param);
  2062 if(e != 0)
  2063 {
  2064    printf("setting scheduling policy and priority failed."));
  2065    return -1;
  2066 }
  2067 e = pthread_getschedparam(thread,&policy;,& param);
  2068 if (e != 0)
  2069 {
  2070    printf("getting scheduling policy and priority failed."));
  2071    return -1;
  2072 }
  2073 
  2074 @endcode
  2075  
  2076 
  2077 @publishedAll
  2078 @externallyDefinedApi
  2079 */                                   
  2080 
  2081 
  2082 /** @fn  pthread_cond_timedwait(pthread_cond_t * cond,pthread_mutex_t * mutex,const struct timespec *abstime)
  2083 @param cond
  2084 @param mutex
  2085 @param abstime
  2086 @return   If successful, the pthread_cond_timedwait function will return zero.
  2087 Otherwise an error number will be returned to
  2088 indicate the error.
  2089 
  2090   The pthread_cond_timedwait function atomically blocks the current thread waiting on the condition,
  2091 specified by the cond,and unblocks the mutex specified by the mutex.
  2092 
  2093  The waiting thread unblocks only after another thread calls pthread_cond_signal,pthread_cond_broadcast with the same condition variable,
  2094 or if the system time reaches the time specified in abstime,and the current thread reacquires the lock on the mutex.
  2095 
  2096 
  2097 
  2098 Examples:
  2099 @code
  2100 struct testdata
  2101 {
  2102 pthread_mutex mutex;
  2103 pthread_cond_t cond;
  2104 };
  2105 static struct testdata td;
  2106 int rc;
  2107 struct timespec timeout;
  2108 struct timeval curtime;
  2109 if(pthread_mutex_lock(&td.mutex)!=0)
  2110   {
  2111   fprintf(stderr,"fail");
  2112   return -1;
  2113   }
  2114 if(gettimeofday(&curtime,NULL)!=0)
  2115   {
  2116   fprintf(stderr,"fail");
  2117   return -1;
  2118   }
  2119 timeout.tv_sec=curtime.tv_sec;
  2120 timeout.tv_nsec=curtime.tv_nsec;
  2121 timeout.tv_sec+=TIMEOUT;
  2122 fprintf(stderr,"thread is waiting on the cond");
  2123 rc=pthread_cond_timedwait(&td.cond,&td.mutex,&timeout);
  2124 if(rc!=0)
  2125   {
  2126   if(rc==ETIMEDOUT)
  2127     {
  2128     fprintf(stderr,"thread stops when time is out");
  2129     return -1;
  2130     }
  2131   else
  2132    {
  2133    fprintf(stderr,"pthread_cond_timedwait return");
  2134    return -1;
  2135    }
  2136   }
  2137 fprintf(stderr,"thread wakened up");
  2138 pthread_mutex_unlock(&td.mutex);
  2139 @endcode
  2140 @see pthread_exit()
  2141 @see pthread_join()
  2142 
  2143 
  2144  
  2145 
  2146 @publishedAll
  2147 @externallyDefinedApi
  2148 */