os/ossrv/genericopenlibs/openenvcore/libpthread/inc/pthread.dosc
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libpthread/inc/pthread.dosc	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2148 @@
     1.4 +/** @file ../inc/pthread.h
     1.5 +@internalComponent
     1.6 +*/
     1.7 +
     1.8 +/** @def POSIX_THREAD_KEYS_MAX
     1.9 +
    1.10 +Represents maximum value
    1.11 +
    1.12 +@publishedAll
    1.13 +@externallyDefinedApi
    1.14 +*/
    1.15 +
    1.16 +/** @def PTHREAD_STACK_MIN  
    1.17 +
    1.18 +Minimum supported stack size for a thread
    1.19 +                 
    1.20 +@publishedAll
    1.21 +@externallyDefinedApi
    1.22 +*/
    1.23 +
    1.24 +/** @def POSIX_THREAD_THREADS_MAX            
    1.25 +
    1.26 +Thread max. Value is 64
    1.27 +
    1.28 +@publishedAll
    1.29 +@externallyDefinedApi
    1.30 +*/
    1.31 +
    1.32 +/** @def PTHREAD_THREADS_MAX
    1.33 +
    1.34 +Maximum number of threads supported per process. Value is 1024
    1.35 +
    1.36 +@publishedAll
    1.37 +@externallyDefinedApi
    1.38 +*/
    1.39 +
    1.40 +/** @def SEM_VALUE_MAX
    1.41 +
    1.42 +Semaphores have a maximum value past which they cannot be incremented. The macro SEM_VALUE_MAX is defined to be this maximum value.
    1.43 +
    1.44 +@publishedAll
    1.45 +@externallyDefinedApi
    1.46 +*/
    1.47 +
    1.48 +/** @def PTHREAD_COND_INITIALIZER
    1.49 +
    1.50 +Value is 4. Describes condition initializer.
    1.51 +
    1.52 +@publishedAll
    1.53 +@externallyDefinedApi
    1.54 +*/
    1.55 +
    1.56 +/** @def SEM_NSEMS_MAX          
    1.57 +
    1.58 +The maximum number of semaphores a process can have.value is 1024
    1.59 +             
    1.60 +@publishedAll
    1.61 +@released
    1.62 +*/
    1.63 +
    1.64 +/** @def POSIX_SEM_NSEMS_MAX       
    1.65 +
    1.66 +Number of semaphores a process can have. 
    1.67 +          
    1.68 +@publishedAll
    1.69 +@released
    1.70 +*/
    1.71 +
    1.72 +/** @def POSIX_THREAD_DESTRUCTOR_ITERATIONS  
    1.73 +
    1.74 +Controlling the iterations of destructors for thread-specific data.
    1.75 +
    1.76 +@publishedAll
    1.77 +@released
    1.78 +*/
    1.79 +
    1.80 +/** @typedef typedef int pthread_once_t
    1.81 +
    1.82 +Used for dynamic package initialization.
    1.83 +
    1.84 +@publishedAll
    1.85 +@externallyDefinedApi
    1.86 +*/
    1.87 +
    1.88 +/** @typedef typedef struct _pthread_condattr_t*   pthread_condattr_t
    1.89 +
    1.90 +Used to identify a condition attribute object
    1.91 +
    1.92 +@publishedAll
    1.93 +@externallyDefinedApi
    1.94 +*/
    1.95 +
    1.96 +/** @struct pthread_mutex_t 
    1.97 +
    1.98 +Thread mutex type. Used for mutexes.
    1.99 +
   1.100 +@publishedAll
   1.101 +@externallyDefinedApi
   1.102 +*/
   1.103 +
   1.104 +/** @struct pthread_mutexattr_t
   1.105 +
   1.106 +Used to identify a mutex attribute object. 
   1.107 +
   1.108 +@publishedAll
   1.109 +@externallyDefinedApi
   1.110 +*/
   1.111 +
   1.112 +/** @struct pthread_cond_t
   1.113 +
   1.114 +Used for condition variables. 
   1.115 +
   1.116 +@publishedAll
   1.117 +@externallyDefinedApi
   1.118 +*/
   1.119 +
   1.120 +/** @fn  pthread_create(pthread_t *threadhdl, pthread_attr_t *attrib, thread_begin_routine begin_routine, void *param)
   1.121 +@param threadhdl
   1.122 +@param attrib
   1.123 +@param begin_routine
   1.124 +@param *param
   1.125 +@return   If successful, the pthread_create function will return zero.
   1.126 +Otherwise an error number will be returned to
   1.127 +indicate the error.
   1.128 +
   1.129 +  The pthread_create function is used to create a new thread, with attributes specified by attrib ,
   1.130 +within a process.
   1.131 +If attrib is NULL ,
   1.132 +the default attributes are used.
   1.133 +If the attributes specified by attrib are modified later, the thread's attributes are not affected.
   1.134 +Upon
   1.135 +successful completion pthread_create will store the ID of the created thread in the location specified by threadhdl .
   1.136 +
   1.137 + The thread is created executing begin_routine with param as its sole argument.
   1.138 +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.
   1.139 +Note that the thread in which main was originally invoked differs from this.
   1.140 +When it returns from main ,
   1.141 +the effect is as if there was an implicit call to exit using the return value of main as the exit status.
   1.142 +
   1.143 +
   1.144 +
   1.145 +Examples:
   1.146 +@code
   1.147 +void *a_thread_func_1_1(void*)
   1.148 +{
   1.149 + return NULL;
   1.150 +}
   1.151 +int XYZ()
   1.152 +{
   1.153 + pthread_t new_th;
   1.154 + if(pthread_create(&new;_th, NULL, a_thread_func_1_1, NULL) != 0)
   1.155 + {
   1.156 +  perror("Error creating thread
   1.157 +");
   1.158 +  return -1;
   1.159 + }
   1.160 +}
   1.161 +
   1.162 +@endcode
   1.163 +@see pthread_exit()
   1.164 +@see pthread_join()
   1.165 +
   1.166 +
   1.167 + 
   1.168 +
   1.169 +@publishedAll
   1.170 +@externallyDefinedApi
   1.171 +*/ 
   1.172 +
   1.173 +/** @fn  pthread_self(void)
   1.174 +
   1.175 +@return   The pthread_self function returns the thread ID of the calling thread.
   1.176 +
   1.177 +  The pthread_self function returns the thread ID of the calling thread.
   1.178 +
   1.179 +
   1.180 +
   1.181 +Examples:
   1.182 +@code
   1.183 +pthread_t new_th2;
   1.184 +new_th2=pthread_self();
   1.185 +
   1.186 +@endcode
   1.187 +@see pthread_create()
   1.188 +@see pthread_equal()
   1.189 +
   1.190 +
   1.191 + 
   1.192 +
   1.193 +@publishedAll
   1.194 +@externallyDefinedApi
   1.195 +*/                    
   1.196 +
   1.197 +/** @fn  pthread_equal(pthread_t t1, pthread_t t2)
   1.198 +@param t1
   1.199 +@param t2
   1.200 +@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.
   1.201 +
   1.202 +  The pthread_equal function compares the thread IDs t1 and t2 .
   1.203 +
   1.204 +Examples:
   1.205 +@code
   1.206 +void *a_thread_func_1_2(void*)
   1.207 +{
   1.208 + pthread_exit(0);
   1.209 + return NULL;
   1.210 +}
   1.211 +void XYZ()
   1.212 +{
   1.213 +pthread_t new_th1, new_th2;
   1.214 + /* Create a new thread. */
   1.215 + if(pthread_create(&new;_th1, NULL, a_thread_func_1_2, NULL) != 0)
   1.216 + {
   1.217 +  perror("Error creating thread
   1.218 +");
   1.219 +  return -1;
   1.220 + }
   1.221 + /* Create another new thread. */
   1.222 + if(pthread_create(&new;_th2, NULL, a_thread_func_1_2, NULL) != 0)
   1.223 + {
   1.224 +  perror("Error creating thread
   1.225 +");
   1.226 +  return -1;
   1.227 + }
   1.228 + /* Call pthread_equal() and pass to it the 2 new threads.
   1.229 +  * It should return a zero value, indicating that
   1.230 +  * they are not equal. */
   1.231 + if(pthread_equal(new_th1, new_th2) != 0)
   1.232 + {
   1.233 +  printf("pthread_equal FAILED
   1.234 +");
   1.235 +  return -1;
   1.236 + }
   1.237 +}
   1.238 +
   1.239 +@endcode
   1.240 +@see pthread_create()
   1.241 +@see pthread_exit()
   1.242 +
   1.243 +
   1.244 + 
   1.245 +
   1.246 +@publishedAll
   1.247 +@externallyDefinedApi
   1.248 +*/
   1.249 +
   1.250 +/** @fn  pthread_join(pthread_t thrHandle, void **retValPtr)
   1.251 +@param thrHandle
   1.252 +@param retValPtr
   1.253 +@return   If successful, the pthread_join function will return zero.
   1.254 +Otherwise an error number will be returned to
   1.255 +indicate the error.
   1.256 +
   1.257 +  The pthread_join function suspends execution of the calling thread until the target thrHandle terminates unless the target thrHandle has already terminated.
   1.258 +
   1.259 + 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 .
   1.260 +When a pthread_join returns successfully, the target thread has been terminated.
   1.261 +The results
   1.262 +of multiple simultaneous calls to pthread_join specifying the same target thread are undefined.
   1.263 +
   1.264 +
   1.265 +
   1.266 +Examples:
   1.267 +@code
   1.268 +/* Thread's function. */
   1.269 +void *a_thread_func_1_1(void*)
   1.270 +{
   1.271 + int i;
   1.272 + printf("Wait for 3 seconds for thread to finish execution:0);
   1.273 + for(i=1;i<4;i++)
   1.274 + {
   1.275 +  printf("Waited (%d) second0, i);
   1.276 +  sleep(1);
   1.277 + }
   1.278 + return NULL;
   1.279 +}
   1.280 +int XYZ()
   1.281 +{
   1.282 + pthread_t new_th;
   1.283 + /* Create a new thread. */
   1.284 + if(pthread_create(&new;_th, NULL, a_thread_func_1_1, NULL) != 0)
   1.285 + {
   1.286 +  perror("Error creating thread
   1.287 +");
   1.288 +  return -1;
   1.289 + }
   1.290 + /* Wait for thread to return */
   1.291 + if(pthread_join(new_th, NULL) != 0)
   1.292 + {
   1.293 +  perror("Error in pthread_join()
   1.294 +");
   1.295 +  return -1;
   1.296 + }
   1.297 +
   1.298 +@endcode
   1.299 +@see wait()
   1.300 +@see pthread_create()
   1.301 +
   1.302 +
   1.303 + 
   1.304 +
   1.305 +@publishedAll
   1.306 +@externallyDefinedApi
   1.307 +*/
   1.308 +
   1.309 +/** @fn  pthread_detach(pthread_t thrHandle)
   1.310 +@param thrHandle
   1.311 +@return   If successful, the pthread_detach function will return zero.
   1.312 +Otherwise an error number will be returned to
   1.313 +indicate the error.
   1.314 +
   1.315 +  The pthread_detach function is used to indicate to the implementation that storage for the
   1.316 +thread thrHandle can be reclaimed when the thread terminates.
   1.317 +If thrHandle has not terminated, pthread_detach will not cause it to terminate.
   1.318 +The effect of multiple pthread_detach calls on the same target thread is unspecified.
   1.319 +
   1.320 +Examples:
   1.321 +@code
   1.322 +void *a_thread_func_1_1(void*)
   1.323 +{
   1.324 + sleep(10);
   1.325 + return NULL;
   1.326 +}
   1.327 +int main_1_1()
   1.328 +{
   1.329 + pthread_attr_t new_attr;
   1.330 + pthread_t new_th;
   1.331 + int ret;
   1.332 + /* Initialize attribute */
   1.333 + if(pthread_attr_init(&new;_attr) != 0)
   1.334 + {
   1.335 +  perror("Cannot initialize attribute object
   1.336 +");
   1.337 +  return -1;
   1.338 + }
   1.339 + /* Set the attribute object to be joinable */
   1.340 + if(pthread_attr_setdetachstate(&new;_attr, PTHREAD_CREATE_JOINABLE) != 0)
   1.341 + {
   1.342 +  perror("Error in pthread_attr_setdetachstate()
   1.343 +");
   1.344 +  return -1;
   1.345 + }
   1.346 + /* Create the thread */
   1.347 + if(pthread_create(&new;_th, &new;_attr, a_thread_func_1_1, NULL) != 0)
   1.348 + {
   1.349 +  perror("Error creating thread
   1.350 +");
   1.351 +  return -1;
   1.352 + }
   1.353 + /* Detach the thread. */
   1.354 + if(pthread_detach(new_th) != 0)
   1.355 + {
   1.356 +  printf("Error detaching thread
   1.357 +");
   1.358 +  return -1;
   1.359 + }
   1.360 +
   1.361 +@endcode
   1.362 +@see pthread_join()
   1.363 +
   1.364 +
   1.365 + 
   1.366 +
   1.367 +@publishedAll
   1.368 +@externallyDefinedApi
   1.369 +*/
   1.370 +
   1.371 +/** @fn  pthread_exit(void *retValPtr)
   1.372 +@param retValPtr
   1.373 +@return   The pthread_exit function cannot return to its caller.
   1.374 +
   1.375 +  The pthread_exit function terminates the calling thread and makes the value retValPtr available to any successful join with the terminating thread.
   1.376 +Thread termination does not release any application
   1.377 +visible process resources, including, but not limited to, mutexes and
   1.378 +file descriptors, nor does it perform any process level cleanup
   1.379 +actions, including, but not limited to, calling atexit routines that may exist.
   1.380 +
   1.381 + 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
   1.382 +it.
   1.383 +The function's return value serves as the thread's exit status.
   1.384 +
   1.385 + The behavior of pthread_exit is undefined if called from a cancellation handler or destructor function
   1.386 +that was invoked as the result of an implicit or explicit call to pthread_exit .
   1.387 +
   1.388 + After a thread has terminated, the result of access to local (auto)
   1.389 +variables of the thread is undefined.
   1.390 +Thus, references to local variables
   1.391 +of the exiting thread should not be used for the pthread_exit retValPtr parameter value.
   1.392 +
   1.393 + The process will exit with an exit status of 0 after the last thread has
   1.394 +been terminated.
   1.395 +The behavior is as if the implementation called exit with a zero argument at thread termination time.
   1.396 +
   1.397 +Examples:
   1.398 +@code
   1.399 +/* Thread's function. */
   1.400 +void *a_thread_func_1_1(void*)
   1.401 +{
   1.402 + /* .. Do some thing .. */
   1.403 + pthread_exit((void*)RETURN_CODE);
   1.404 +}
   1.405 +
   1.406 +@endcode
   1.407 +@see _exit()
   1.408 +@see exit()
   1.409 +@see pthread_create()
   1.410 +@see pthread_join()
   1.411 +
   1.412 +
   1.413 + 
   1.414 +
   1.415 +@publishedAll
   1.416 +@externallyDefinedApi
   1.417 +*/
   1.418 + 
   1.419 +/** @fn  pthread_attr_init(pthread_attr_t *attrib)
   1.420 +@param attrib
   1.421 +
   1.422 +Note: This description also covers the following functions -
   1.423 + 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() 
   1.424 +
   1.425 +@return   If successful, these functions return 0.
   1.426 +Otherwise, an error number is returned to indicate the error.
   1.427 +
   1.428 +  Thread attributes are used to specify parameters to pthread_create .
   1.429 +One attribute object can be used in multiple calls to pthread_create ,
   1.430 +with or without modifications between calls.
   1.431 +
   1.432 + The pthread_attr_init function initializes attrib with all the default thread attributes.
   1.433 +
   1.434 + The pthread_attr_destroy function destroys attrib .
   1.435 +
   1.436 + The pthread_attr_set* functions set the attribute that corresponds to each function name.
   1.437 +
   1.438 + The pthread_attr_get* functions copy the value of the attribute that corresponds to each function name
   1.439 +to the location pointed to by the second function parameter.
   1.440 +
   1.441 +Examples:
   1.442 +@code
   1.443 +/* ***************************************************** */
   1.444 +/* Example for pthread_attr_init & pthread_attr_destroy  */
   1.445 +/* ***************************************************** */
   1.446 +pthread_attr_t new_attr;
   1.447 +/* Initialize attribute */
   1.448 +if(pthread_attr_init(&new;_attr) != 0)
   1.449 +{
   1.450 +  printf("Cannot initialize attribute object
   1.451 +");
   1.452 +  return -1; /* or exit */
   1.453 +}
   1.454 +/* Create thread */
   1.455 +/* Destroy attribute */
   1.456 +if(pthread_attr_destroy(&new;_attr) != 0)
   1.457 +{
   1.458 +  perror("Cannot destroy the attribute object
   1.459 +");
   1.460 +  return -1; /* or exit*/
   1.461 +}
   1.462 +
   1.463 +@endcode
   1.464 +@code
   1.465 +/* ***************************************************** */
   1.466 +/* Example for pthread_attr_getdetachstate               */
   1.467 +/* ***************************************************** */
   1.468 +pthread_attr_t new_attr;
   1.469 +int detach_state;
   1.470 +/* Initialize attribute */
   1.471 +if(pthread_attr_init(&new;_attr) != 0)
   1.472 +{
   1.473 +  printf("Cannot initialize attribute object
   1.474 +");
   1.475 +  return -1;
   1.476 +}
   1.477 +if(pthread_attr_getdetachstate(&new;_attr, &detach;_state) != 0)
   1.478 +{
   1.479 +  printf("Cannot get the state
   1.480 +");
   1.481 +  return -1;
   1.482 +}
   1.483 +if(detach_state == PTHREAD_CREATE_JOINABLE)
   1.484 +{
   1.485 +  printf("State is joinable 
   1.486 +");
   1.487 +}
   1.488 +else
   1.489 +{
   1.490 +  printf("State is detached 
   1.491 +");
   1.492 +}
   1.493 +/* Create thread */
   1.494 +/* Destroy attribute */
   1.495 +
   1.496 +@endcode
   1.497 +@code
   1.498 +/* ***************************************************** */
   1.499 +/* Example for pthread_attr_getschedpolicy               */
   1.500 +/* ***************************************************** */
   1.501 +pthread_attr_t new_attr;
   1.502 +int rc;
   1.503 +int policy;
   1.504 +/* Initialize attribute */
   1.505 +if(pthread_attr_init(&new;_attr) != 0)
   1.506 +{
   1.507 +  printf("Cannot initialize attribute object
   1.508 +");
   1.509 +  return -1; /* or exit */
   1.510 +}
   1.511 +rc = pthread_attr_getschedpolicy(new_attr, &policy;);
   1.512 +if( rc != 0) {
   1.513 +  printf("pthread_attr_getschedpolicy failed
   1.514 +");
   1.515 +  return -1;
   1.516 +}
   1.517 +switch(policy) {
   1.518 + case SCHED_FIFO:
   1.519 +       printf("Scheduling policy: SCHED_FIFO 0);
   1.520 +       break;
   1.521 + case SCHED_RR:
   1.522 +       printf("Scheduling policy: SCHED_RR 
   1.523 +");
   1.524 +       break;
   1.525 + case SCHED_OTHER:
   1.526 +       printf("Scheduling policy: SCHED_OTHER 
   1.527 +");
   1.528 +       break;
   1.529 +}
   1.530 +/* Create thread */
   1.531 +/* Destroy attribute */
   1.532 +
   1.533 +@endcode
   1.534 +@code
   1.535 +/* ***************************************************** */
   1.536 +/* Example for pthread_attr_getscope                     */
   1.537 +/* ***************************************************** */
   1.538 +pthread_attr_t new_attr;
   1.539 +int rc;
   1.540 +int scope;
   1.541 +/* Initialize attribute */
   1.542 +if(pthread_attr_init(&new;_attr) != 0)
   1.543 +{
   1.544 +  printf("Cannot initialize attribute object
   1.545 +");
   1.546 +  return -1; /* or exit */
   1.547 +}
   1.548 +rc = pthread_attr_getscope(new_attr, &scope;);
   1.549 +if( rc != 0) {
   1.550 +  printf("pthread_attr_getscope failed");
   1.551 +  return -1;
   1.552 +}
   1.553 +switch(scope) {
   1.554 + case SYSTEMSCOPE:
   1.555 +       printf("scope: System 
   1.556 + ");
   1.557 +       break;
   1.558 + case PROCESSSCOPE:
   1.559 +       printf("scope: Process 
   1.560 + ");
   1.561 +       break;
   1.562 +}
   1.563 +/* Create thread */
   1.564 +/* Destroy attribute */
   1.565 +
   1.566 +@endcode
   1.567 +@code
   1.568 +/* ***************************************************** */
   1.569 +/* Example for pthread_attr_getstacksize                 */
   1.570 +/* ***************************************************** */
   1.571 +pthread_attr_t new_attr;
   1.572 +size_t ssize;
   1.573 +int rc;
   1.574 +/* Initialize attribute */
   1.575 +if(pthread_attr_init(&new;_attr) != 0)
   1.576 +{
   1.577 +  printf("Cannot initialize attribute object
   1.578 +");
   1.579 +  return -1; /* or exit */
   1.580 +}
   1.581 +/* Get the default stack_size value */
   1.582 +rc = pthread_attr_getstacksize(&new;_attr, &stack;_size); 
   1.583 +if( rc != 0) {
   1.584 +  printf("pthread_attr_getstacksize failed");
   1.585 +  return -1;
   1.586 +}
   1.587 +printf("ssize = %lu
   1.588 +", stack_size);
   1.589 +/* Create thread */
   1.590 +/* Destroy attribute */
   1.591 +
   1.592 +@endcode
   1.593 +@code
   1.594 +/* ***************************************************** */
   1.595 +/* Example for pthread_attr_getschedparam               */
   1.596 +/* ***************************************************** */
   1.597 +pthread_attr_t         attr;
   1.598 +int                    rc=0;
   1.599 +struct sched_param     param;
   1.600 +struct sched_param     param2;
   1.601 +rc = pthread_attr_init(&attr;);
   1.602 +if(rc != 0) {
   1.603 +  printf("pthread_attr_init failed
   1.604 +");
   1.605 +  return -1;
   1.606 +}
   1.607 +param.sched_priority = 50;
   1.608 +rc = pthread_attr_setschedparam(&attr;, & param);
   1.609 +if(rc != 0) {
   1.610 +  printf("pthread_attr_setschedparam failed
   1.611 +");
   1.612 +  return -1;
   1.613 +}
   1.614 +rc = pthread_attr_getschedparam(&attr;, & param2);
   1.615 +if(rc != 0) {
   1.616 +  printf("pthread_attr_getschedparam failed
   1.617 +");
   1.618 +  return -1;
   1.619 +}
   1.620 +/* priority will be stored in param2.sched_priority */
   1.621 +/* Create thread */
   1.622 +/* Destroy attribute */
   1.623 +
   1.624 +@endcode
   1.625 +@code
   1.626 +/* ***************************************************** */
   1.627 +/* Example for pthread_attr_setdetachstate               */
   1.628 +/* ***************************************************** */
   1.629 +pthread_attr_t new_attr;
   1.630 +int detach_state;
   1.631 +/* Initialize attribute */
   1.632 +if(pthread_attr_init(&new;_attr) != 0)
   1.633 +{
   1.634 +  perror("Cannot initialize attribute object
   1.635 +");
   1.636 +  return -1;
   1.637 +}
   1.638 +/* Set the attribute object to PTHREAD_CREATE_JOINABLE. */
   1.639 +if(pthread_attr_setdetachstate(&new;_attr, PTHREAD_CREATE_JOINABLE) != 0)
   1.640 +{
   1.641 +  perror("Error in pthread_attr_setdetachstate()
   1.642 +");
   1.643 +  return -1;
   1.644 +}
   1.645 +/* Create thread */
   1.646 +/* Destroy attribute */
   1.647 +
   1.648 +@endcode
   1.649 +@code
   1.650 +/* ***************************************************** */
   1.651 +/* Example for pthread_attr_setschedparam               */
   1.652 +/* ***************************************************** */
   1.653 +pthread_attr_t         attr;
   1.654 +int                    rc=0;
   1.655 +struct sched_param     param;
   1.656 +rc = pthread_attr_init(&attr;);
   1.657 +if(rc != 0) {
   1.658 +  printf("pthread_attr_init failed
   1.659 +");
   1.660 +  return -1;
   1.661 +}
   1.662 +param.sched_priority = 50;
   1.663 +rc = pthread_attr_setschedparam(&attr;, & param);
   1.664 +if(rc != 0) {
   1.665 +  printf("pthread_attr_setschedparam failed
   1.666 +");
   1.667 +  return -1;
   1.668 +}
   1.669 +/* Create thread */
   1.670 +/* Destroy attribute */
   1.671 +
   1.672 +@endcode
   1.673 +@code
   1.674 +/* ***************************************************** */
   1.675 +/* Example for pthread_attr_setschedpolicy               */
   1.676 +/* ***************************************************** */
   1.677 +pthread_attr_t attr;
   1.678 +int rc;
   1.679 +int policy = SCHED_RR;
   1.680 +if(pthread_attr_init(&attr;) != 0) {
   1.681 +  printf("Error on pthread_attr_init()
   1.682 +");
   1.683 +  return -1;
   1.684 +}
   1.685 + 
   1.686 +if((rc=pthread_attr_setschedpolicy(&attr;,policy)) != 0) {
   1.687 +      printf("Error on pthread_attr_setschedpolicy()	 rc=%d
   1.688 +", rc);
   1.689 +      return -1;
   1.690 +}
   1.691 +/* Create thread */
   1.692 +/* Destroy attribute */
   1.693 +
   1.694 +@endcode
   1.695 +@code
   1.696 +/* ***************************************************** */
   1.697 +/* Example for pthread_attr_setstacksize                 */
   1.698 +/* ***************************************************** */
   1.699 +pthread_attr_t attr;
   1.700 +int rc;
   1.701 +int policy = SCHED_RR;
   1.702 +if(pthread_attr_init(&attr;) != 0) {
   1.703 +  printf("Error on pthread_attr_init()
   1.704 +");
   1.705 +  return -1;
   1.706 +}
   1.707 + 
   1.708 +if((rc=pthread_attr_setstacksize(&attr;,8192)) != 0) {
   1.709 +      printf("Error on pthread_attr_setstacksize()	 rc=%d
   1.710 +", rc);
   1.711 +      return -1;
   1.712 +}
   1.713 +/* Create thread */
   1.714 +/* Destroy attribute */
   1.715 +
   1.716 +@endcode
   1.717 +@code
   1.718 +/* ***************************************************** */
   1.719 +/* Example for pthread_attr_setscope                     */
   1.720 +/* ***************************************************** */
   1.721 +pthread_attr_t attr;
   1.722 +int rc;
   1.723 +/* Initialize attr */
   1.724 +rc = pthread_attr_init(&attr;);
   1.725 +if( rc != 0) {
   1.726 +  perror("pthread_attr_init failed");
   1.727 +  return -1;
   1.728 +}
   1.729 +rc = pthread_attr_setscope(&attr;, PTHREAD_SCOPE_SYSTEM); 
   1.730 +if (rc != 0 ) {
   1.731 +  perror("PTHREAD_SCOPE_SYSTEM is not supported");
   1.732 +  return -1;
   1.733 +}
   1.734 +/* Create thread */
   1.735 +/* Destroy attribute */
   1.736 +
   1.737 +@endcode
   1.738 +@see pthread_create()
   1.739 +
   1.740 +
   1.741 + 
   1.742 +
   1.743 +@publishedAll
   1.744 +@externallyDefinedApi
   1.745 +*/
   1.746 +
   1.747 +/** @fn  pthread_attr_destroy(pthread_attr_t *attrib)
   1.748 +@param attrib
   1.749 +Refer  pthread_attr_init() for the documentation
   1.750 +@see pthread_create()
   1.751 +
   1.752 +
   1.753 + 
   1.754 +
   1.755 +@publishedAll
   1.756 +@externallyDefinedApi
   1.757 +*/
   1.758 +
   1.759 +/** @fn  pthread_attr_getdetachstate(const pthread_attr_t *attrib, int *detState)
   1.760 +@param attrib
   1.761 +@param detState
   1.762 +Refer  pthread_attr_init() for the documentation
   1.763 +@see pthread_create()
   1.764 +
   1.765 +
   1.766 + 
   1.767 +
   1.768 +@publishedAll
   1.769 +@externallyDefinedApi
   1.770 +*/
   1.771 +
   1.772 +/** @fn  pthread_attr_setdetachstate(pthread_attr_t *attrib, int detState)
   1.773 +@param attrib
   1.774 +@param detState
   1.775 +Refer  pthread_attr_init() for the documentation
   1.776 +@see pthread_create()
   1.777 +
   1.778 +
   1.779 + 
   1.780 +
   1.781 +@publishedAll
   1.782 +@externallyDefinedApi
   1.783 +*/               
   1.784 +                          
   1.785 +/** @fn  pthread_attr_getstacksize(const pthread_attr_t *attrib, size_t *stkSize)
   1.786 +@param attrib
   1.787 +@param stkSize
   1.788 +Refer  pthread_attr_init() for the documentation
   1.789 +@see pthread_create()
   1.790 +
   1.791 +
   1.792 + 
   1.793 +
   1.794 +@publishedAll
   1.795 +@externallyDefinedApi
   1.796 +*/
   1.797 +
   1.798 +/** @fn  pthread_attr_setstacksize(pthread_attr_t *attrib, size_t stkSize)
   1.799 +@param attrib
   1.800 +@param stkSize
   1.801 +Refer  pthread_attr_init() for the documentation
   1.802 +@see pthread_create()
   1.803 +
   1.804 +
   1.805 + 
   1.806 +
   1.807 +@publishedAll
   1.808 +@externallyDefinedApi
   1.809 +*/                                                                              
   1.810 +
   1.811 +/** @fn  pthread_once(pthread_once_t *once_control, thread_init_routine init_routine)
   1.812 +@param once_control
   1.813 +@param init_routine
   1.814 +@return   If successful, the pthread_once function will return zero.
   1.815 +Otherwise an error number will be returned to
   1.816 +indicate the error.
   1.817 +
   1.818 +  The first call to pthread_once by any thread in a process, with a given once_control ,
   1.819 +will call the init_routine with no arguments.
   1.820 +Subsequent calls to pthread_once with the same once_control will not call the init_routine .
   1.821 +On return from pthread_once ,
   1.822 +it is guaranteed that init_routine has completed.
   1.823 +The once_control parameter is used to determine whether the associated initialization
   1.824 +routine has been called.
   1.825 +
   1.826 + The constant PTHREAD_ONCE_INIT is defined by header \#include \<pthread.h\> .
   1.827 +
   1.828 + The behavior of pthread_once is undefined if once_control has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT .
   1.829 +
   1.830 +Examples:
   1.831 +@code
   1.832 +/* The init function that pthread_once calls */
   1.833 +void an_init_func_1_1()
   1.834 +{
   1.835 +printf (" Initialized ..
   1.836 +");
   1.837 +}
   1.838 +int XYZ()
   1.839 +{
   1.840 + pthread_once_t once_control = PTHREAD_ONCE_INIT;
   1.841 + /* Call pthread_once, passing it the once_control */
   1.842 + pthread_once(&once;_control, an_init_func_1_1);
   1.843 + /* Call pthread_once again. The init function should not be
   1.844 +  * called. */
   1.845 + pthread_once(&once;_control, an_init_func_1_1);
   1.846 +}
   1.847 +
   1.848 +@endcode
   1.849 + 
   1.850 +
   1.851 +@publishedAll
   1.852 +@externallyDefinedApi
   1.853 +*/
   1.854 +
   1.855 +/** @fn  pthread_mutexattr_init(pthread_mutexattr_t *attr)
   1.856 +@param attr
   1.857 +Note: This description also covers the following functions -
   1.858 + pthread_mutexattr_destroy()  pthread_mutexattr_settype()  pthread_mutexattr_gettype()  pthread_mutexattr_getpshared()  pthread_mutexattr_setpshared() 
   1.859 +
   1.860 +@return   If successful, these functions return 0.
   1.861 +Otherwise, an error number is returned to indicate the error.
   1.862 +
   1.863 +  Mutex attributes are used to specify parameters to pthread_mutex_init .
   1.864 +One attribute object can be used in multiple calls to pthread_mutex_init ,
   1.865 +with or without modifications between calls.
   1.866 +
   1.867 + The pthread_mutexattr_init function initializes attr with all the default mutex attributes.
   1.868 +
   1.869 + The pthread_mutexattr_destroy function destroys attr .
   1.870 +
   1.871 + The pthread_mutexattr_set* functions set the attribute that corresponds to each function name.
   1.872 +
   1.873 + The pthread_mutexattr_get* functions copy the value of the attribute that corresponds to each function name
   1.874 +to the location pointed to by the second function parameter.
   1.875 +
   1.876 +Examples:
   1.877 +@code
   1.878 +pthread_mutexattr_t mta;
   1.879 + int rc;
   1.880 + /* Initialize a mutex attributes object */
   1.881 + if((rc=pthread_mutexattr_init(&mta;)) != 0)
   1.882 + {
   1.883 +  fprintf(stderr,"Cannot initialize mutex attributes object
   1.884 +");
   1.885 +  return -1;
   1.886 + }
   1.887 + /* Destroy the mutex attributes object */
   1.888 + if(pthread_mutexattr_destroy(&mta;) != 0)
   1.889 + {
   1.890 +  fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
   1.891 +", rc);
   1.892 +  return -1;
   1.893 + }
   1.894 +
   1.895 +@endcode
   1.896 +@code
   1.897 + pthread_mutexattr_t mta;
   1.898 + int pshared;
   1.899 + /* Initialize a mutex attributes object */
   1.900 + if(pthread_mutexattr_init(&mta;) != 0)
   1.901 + {
   1.902 +  perror("Error at pthread_mutexattr_init()
   1.903 +");
   1.904 +  return -1;
   1.905 + }
   1.906 +  /* The default 'pshared' attribute is PTHREAD_PROCESS_PRIVATE  */
   1.907 + if(pthread_mutexattr_getpshared(&mta;, &pshared;) != 0)
   1.908 + {
   1.909 +  fprintf(stderr,"Error obtaining the attribute process-shared
   1.910 +");
   1.911 +  return -1;
   1.912 + }
   1.913 +if (pshared != PTHREAD_PROCESS_PRIVATE)
   1.914 +     printf (" pshared is NOT PTHREAD_PROCESS_PRIVATE
   1.915 +");
   1.916 +
   1.917 +@endcode
   1.918 +@code
   1.919 + pthread_mutexattr_t mta;
   1.920 + int type;
   1.921 + /* Initialize a mutex attributes object */
   1.922 + if(pthread_mutexattr_init(&mta;) != 0)
   1.923 + {
   1.924 +  perror("Error at pthread_mutexattr_init()
   1.925 +");
   1.926 +  return -1;
   1.927 + }
   1.928 +  /* The default 'type' attribute  is PTHREAD_MUTEX_DEFAULT  */
   1.929 + if(pthread_mutexattr_gettype(&mta;, &type;) != 0)
   1.930 + {
   1.931 +  fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'
   1.932 +");
   1.933 +  return -1;
   1.934 + }
   1.935 + if(type != PTHREAD_MUTEX_DEFAULT)
   1.936 + {
   1.937 +  printf("FAILED: Incorrect default mutexattr 'type' value: %d
   1.938 +", type);
   1.939 +  return -1;
   1.940 + }
   1.941 +
   1.942 +@endcode
   1.943 +@code
   1.944 +pthread_mutexattr_t mta;
   1.945 + int rc;
   1.946 + /* Initialize a mutex attributes object */
   1.947 + if((rc=pthread_mutexattr_init(&mta;)) != 0)
   1.948 + {
   1.949 +  fprintf(stderr,"Cannot initialize mutex attributes object
   1.950 +");
   1.951 +  return -1;
   1.952 + }
   1.953 + /* Destroy the mutex attributes object */
   1.954 + if(pthread_mutexattr_destroy(&mta;) != 0)
   1.955 + {
   1.956 +  fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
   1.957 +", rc);
   1.958 +  return -1;
   1.959 + }
   1.960 +
   1.961 +@endcode
   1.962 +@code
   1.963 +pthread_mutexattr_t mta;
   1.964 + int ret;
   1.965 + /* Initialize a mutex attributes object */
   1.966 + if(pthread_mutexattr_init(&mta;) != 0)
   1.967 + {
   1.968 +  perror("Error at pthread_mutexattr_init()
   1.969 +");
   1.970 +  return -1;
   1.971 + }
   1.972 + /* Set the 'pshared' attribute to PTHREAD_PROCESS_PRIVATE */
   1.973 + if((ret=pthread_mutexattr_setpshared(&mta;, PTHREAD_PROCESS_PRIVATE)) != 0)
   1.974 + {
   1.975 +  printf("FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_PRIVATE. Error: %d
   1.976 +", ret);
   1.977 +  return -1;
   1.978 + }
   1.979 +
   1.980 +@endcode
   1.981 +@code
   1.982 + pthread_mutexattr_t mta;
   1.983 + int type;
   1.984 + /* Initialize a mutex attributes object */
   1.985 + if(pthread_mutexattr_init(&mta;) != 0)
   1.986 + {
   1.987 +  perror("Error at pthread_mutexattr_init()
   1.988 +");
   1.989 +  return -1;
   1.990 + }
   1.991 + if(pthread_mutexattr_gettype(&mta;, &type;) != 0)
   1.992 + {
   1.993 +  printf("Error getting the attribute 'type'
   1.994 +");
   1.995 +  return -1;
   1.996 + }
   1.997 + if(type != PTHREAD_MUTEX_DEFAULT)
   1.998 + {
   1.999 +  printf("FAILED: Default value of the 'type' attribute is not PTHREAD_MUTEX_DEFAULT 
  1.1000 +");
  1.1001 +  return -1; 
  1.1002 + }
  1.1003 + if(pthread_mutexattr_settype(&mta;, PTHREAD_MUTEX_NORMAL) != 0)
  1.1004 + {
  1.1005 +  printf("FAILED: Error setting the attribute 'type'
  1.1006 +");
  1.1007 +  return -1;
  1.1008 + }
  1.1009 +
  1.1010 +@endcode
  1.1011 +@see pthread_mutex_init()
  1.1012 +
  1.1013 +
  1.1014 + 
  1.1015 +
  1.1016 +@publishedAll
  1.1017 +@externallyDefinedApi
  1.1018 +*/
  1.1019 +
  1.1020 +/** @fn  pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
  1.1021 +@param attr
  1.1022 +Refer  pthread_mutexattr_init() for the documentation
  1.1023 +@see pthread_mutex_init()
  1.1024 +
  1.1025 +
  1.1026 + 
  1.1027 +
  1.1028 +@publishedAll
  1.1029 +@externallyDefinedApi
  1.1030 +*/
  1.1031 +
  1.1032 +/** @fn  pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
  1.1033 +@param attr
  1.1034 +@param pshared
  1.1035 +Refer  pthread_mutexattr_init() for the documentation
  1.1036 +@see pthread_mutex_init()
  1.1037 +
  1.1038 +
  1.1039 + 
  1.1040 +
  1.1041 +@publishedAll
  1.1042 +@externallyDefinedApi
  1.1043 +*/
  1.1044 +
  1.1045 +/** @fn  pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
  1.1046 +@param attr
  1.1047 +@param type
  1.1048 +Refer  pthread_mutexattr_init() for the documentation
  1.1049 +@see pthread_mutex_init()
  1.1050 +
  1.1051 +
  1.1052 + 
  1.1053 +
  1.1054 +@publishedAll
  1.1055 +@externallyDefinedApi
  1.1056 +*/
  1.1057 +
  1.1058 +/** @fn  pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
  1.1059 +@param attr
  1.1060 +@param type # use integer valuses between 1 and 10
  1.1061 +Refer  pthread_mutexattr_init() for the documentation
  1.1062 +@see pthread_mutex_init()
  1.1063 +
  1.1064 +
  1.1065 + 
  1.1066 +
  1.1067 +@publishedAll
  1.1068 +@externallyDefinedApi
  1.1069 +*/
  1.1070 +
  1.1071 +/** @fn  pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
  1.1072 +@param mutex
  1.1073 +@param attr
  1.1074 +@return   If successful, pthread_mutex_init will return zero and put the new mutex id into mutex ,
  1.1075 +otherwise an error number will be returned to indicate the error.
  1.1076 +
  1.1077 +  The pthread_mutex_init function creates a new mutex, with attributes specified with attr .
  1.1078 +If attr is NULL the default attributes are used.
  1.1079 +
  1.1080 +Examples:
  1.1081 +@code
  1.1082 +pthread_mutex_t  mutex;
  1.1083 +int XYZ()
  1.1084 +{
  1.1085 + int rc;
  1.1086 + /* Initialize a mutex object with the default mutex attributes */
  1.1087 + if((rc=pthread_mutex_init(&mutex;,NULL)) != 0)
  1.1088 +        {
  1.1089 +        fprintf(stderr,"Error at pthread_mutex_init(), rc=%d0,rc);
  1.1090 +        return -1;
  1.1091 +        }
  1.1092 +}
  1.1093 +
  1.1094 +@endcode
  1.1095 +@see pthread_mutex_destroy()
  1.1096 +@see pthread_mutex_lock()
  1.1097 +@see pthread_mutex_trylock()
  1.1098 +@see pthread_mutex_unlock()
  1.1099 +
  1.1100 +
  1.1101 + 
  1.1102 +
  1.1103 +@publishedAll
  1.1104 +@externallyDefinedApi
  1.1105 +*/
  1.1106 +
  1.1107 +/** @fn  pthread_mutex_destroy(pthread_mutex_t *mutex)
  1.1108 +@param mutex
  1.1109 +@return   If successful, pthread_mutex_destroy will return zero, otherwise an error number will be returned to
  1.1110 +indicate the error.
  1.1111 +
  1.1112 +  The pthread_mutex_destroy function frees the resources allocated for mutex .
  1.1113 +
  1.1114 +Examples:
  1.1115 +@code
  1.1116 + pthread_mutexattr_t mta;
  1.1117 + int rc;
  1.1118 + /* Initialize a mutex attributes object */
  1.1119 + if((rc=pthread_mutexattr_init(&mta;)) != 0) {
  1.1120 +  fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d
  1.1121 +",rc);
  1.1122 +  return -1;
  1.1123 + }
  1.1124 + /* Destroy the mutex attributes object */
  1.1125 + if((rc=pthread_mutexattr_destroy(&mta;)) != 0) {
  1.1126 +  fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d
  1.1127 +",rc);
  1.1128 +  return -1;
  1.1129 + }
  1.1130 +
  1.1131 +@endcode
  1.1132 +@see pthread_mutex_init()
  1.1133 +@see pthread_mutex_lock()
  1.1134 +@see pthread_mutex_trylock()
  1.1135 +@see pthread_mutex_unlock()
  1.1136 +
  1.1137 +
  1.1138 + 
  1.1139 +
  1.1140 +@publishedAll
  1.1141 +@externallyDefinedApi
  1.1142 +*/
  1.1143 +
  1.1144 +/** @fn  pthread_mutex_lock(pthread_mutex_t *mutex)
  1.1145 +@param mutex
  1.1146 +@return   If successful, pthread_mutex_lock will return zero, otherwise an error number will be returned to
  1.1147 +indicate the error.
  1.1148 +
  1.1149 +  The pthread_mutex_lock function locks mutex .
  1.1150 +If the mutex is already locked, the calling thread will block until the
  1.1151 +mutex becomes available.
  1.1152 +
  1.1153 +Examples:
  1.1154 +@code
  1.1155 +pthread_mutex_t  mutex;
  1.1156 +int XYZ()
  1.1157 +{
  1.1158 + int rc;
  1.1159 + /* Initialize a mutex object with the default mutex attributes */
  1.1160 + if((rc=pthread_mutex_init(&mutex;,NULL)) != 0) {
  1.1161 +  fprintf(stderr,"Error at pthread_mutex_init(), rc=%d
  1.1162 +",rc);
  1.1163 +  return -1;
  1.1164 + }
  1.1165 + /* Lock the mutex using pthread_mutex_lock() */
  1.1166 + if((rc=pthread_mutex_lock(&mutex;)) == 0) {
  1.1167 +  printf(" lock is successful
  1.1168 +");
  1.1169 + }
  1.1170 +}
  1.1171 +
  1.1172 +@endcode
  1.1173 +@see pthread_mutex_destroy()
  1.1174 +@see pthread_mutex_init()
  1.1175 +@see pthread_mutex_trylock()
  1.1176 +@see pthread_mutex_unlock()
  1.1177 +
  1.1178 +
  1.1179 + 
  1.1180 +
  1.1181 +@publishedAll
  1.1182 +@externallyDefinedApi
  1.1183 +*/
  1.1184 +
  1.1185 +/** @fn  pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
  1.1186 +@param mutex
  1.1187 +@param abstime
  1.1188 +@return   If successful, pthread_mutex_timedlock will return zero, otherwise an error number will be returned to
  1.1189 +indicate the error.
  1.1190 +
  1.1191 +  The pthread_mutex_timedlock function will lock mutex .
  1.1192 +If it is already locked the calling thread will block until
  1.1193 +the mutex becomes available or
  1.1194 +the timeout,
  1.1195 +specified by abstime,
  1.1196 +expires.
  1.1197 +The time of the timeout is an absolute time and
  1.1198 +is not relative to the current time.
  1.1199 +
  1.1200 +Examples:
  1.1201 +@code
  1.1202 +#include <sys/time.h>
  1.1203 +#define TIMEOUT 3    
  1.1204 +/* 3 seconds of timeout time for  pthread_mutex_timedlock(). */
  1.1205 +struct timespec timeout;
  1.1206 +struct timeval currsec1;
  1.1207 +int rc;
  1.1208 +pthread_mutex_t  mutex;
  1.1209 +
  1.1210 +
  1.1211 +/* Get the current time before the mutex locked. */
  1.1212 +gettimeofday(&currsec1;, NULL);
  1.1213 +/* Absolute time, not relative. */
  1.1214 +timeout.tv_sec = currsec1.tv_sec + TIMEOUT;
  1.1215 +timeout.tv_nsec = currsec1.tv_usec * 1000;
  1.1216 +printf("Timed mutex lock will block for %d seconds starting from: %ld.%06ld
  1.1217 +", TIMEOUT, (long)currsec1.tv_sec, (long)currsec1.tv_usec);
  1.1218 +rc = pthread_mutex_timedlock(&mutex;, &timeout;);
  1.1219 +if(rc != 0) {
  1.1220 +  if (rc == ETIMEDOUT) {
  1.1221 +   fprintf(stderr,"Thread stops waiting when time is out
  1.1222 +");
  1.1223 +  }
  1.1224 +  else {
  1.1225 +   fprintf(stderr,"pthread_mutex_timedwait return %d
  1.1226 +", rc);
  1.1227 +  }
  1.1228 +}
  1.1229 +fprintf(stderr,"Thread wakened up
  1.1230 +");
  1.1231 +
  1.1232 +@endcode
  1.1233 +@see pthread_mutex_destroy()
  1.1234 +@see pthread_mutex_init()
  1.1235 +@see pthread_mutex_lock()
  1.1236 +@see pthread_mutex_trylock()
  1.1237 +@see pthread_mutex_unlock()
  1.1238 +
  1.1239 +
  1.1240 + 
  1.1241 +
  1.1242 +@publishedAll
  1.1243 +@externallyDefinedApi
  1.1244 +*/
  1.1245 +
  1.1246 +/** @fn  pthread_mutex_trylock(pthread_mutex_t *mutex)
  1.1247 +@param mutex
  1.1248 +@return   If successful, pthread_mutex_trylock will return zero, otherwise an error number will be returned to
  1.1249 +indicate the error.
  1.1250 +
  1.1251 +  The pthread_mutex_trylock function locks mutex .
  1.1252 +If the mutex is already locked, pthread_mutex_trylock will not block waiting for the mutex, but will return an error condition.
  1.1253 +
  1.1254 +Examples:
  1.1255 +@code
  1.1256 +int rc;
  1.1257 +pthread_mutex_t  mutex;
  1.1258 +rc = pthread_mutex_trylock(&mutex;);
  1.1259 +switch (rc)
  1.1260 +{
  1.1261 +   case 0:
  1.1262 +       printf ("Locked successfully
  1.1263 +");
  1.1264 +       break;
  1.1265 +   case EAGAIN:
  1.1266 +       printf ("could not lock, try later.....
  1.1267 +");
  1.1268 +       break;
  1.1269 +}
  1.1270 +
  1.1271 +@endcode
  1.1272 +@see pthread_mutex_destroy()
  1.1273 +@see pthread_mutex_init()
  1.1274 +@see pthread_mutex_lock()
  1.1275 +@see pthread_mutex_unlock()
  1.1276 +
  1.1277 +
  1.1278 + 
  1.1279 +
  1.1280 +@publishedAll
  1.1281 +@externallyDefinedApi
  1.1282 +*/
  1.1283 +
  1.1284 +/** @fn  pthread_mutex_unlock(pthread_mutex_t *mutex)
  1.1285 +@param mutex
  1.1286 +@return   If successful, pthread_mutex_unlock will return zero, otherwise an error number will be returned to
  1.1287 +indicate the error.
  1.1288 +
  1.1289 +  If the current thread holds the lock on mutex ,
  1.1290 +then the pthread_mutex_unlock function unlocks mutex .
  1.1291 +
  1.1292 +Examples:
  1.1293 +@code
  1.1294 +static pthread_mutex_t    mutex = PTHREAD_MUTEX_INITIALIZER;
  1.1295 +int XYZ()
  1.1296 +{
  1.1297 +   int  rc;
  1.1298 + /* Get the mutex using pthread_mutex_lock() */
  1.1299 + if((rc=pthread_mutex_lock(&mutex;)) != 0) {
  1.1300 +  fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d
  1.1301 +",rc);
  1.1302 +  return -1;
  1.1303 + }
  1.1304 + /* Release the mutex using pthread_mutex_unlock() */
  1.1305 + if((rc=pthread_mutex_unlock(&mutex;)) != 0) {
  1.1306 +  printf("unlock failed 
  1.1307 +");
  1.1308 +  return -1;
  1.1309 + }  
  1.1310 +
  1.1311 +@endcode
  1.1312 +@see pthread_mutex_destroy()
  1.1313 +@see pthread_mutex_init()
  1.1314 +@see pthread_mutex_lock()
  1.1315 +@see pthread_mutex_trylock()
  1.1316 +
  1.1317 +
  1.1318 + 
  1.1319 +
  1.1320 +@publishedAll
  1.1321 +@externallyDefinedApi
  1.1322 +*/
  1.1323 +
  1.1324 +/** @fn  pthread_condattr_init(pthread_condattr_t *)
  1.1325 +
  1.1326 +Note: This description also covers the following functions -
  1.1327 + pthread_condattr_destroy() 
  1.1328 +
  1.1329 +@return   If successful, these functions return 0.
  1.1330 +Otherwise, an error number is returned to indicate the error.
  1.1331 +
  1.1332 +  Condition attribute objects are used to specify parameters to pthread_cond_init .
  1.1333 +Current implementation of conditional variables does not support any
  1.1334 +attributes, so these functions are not very useful.
  1.1335 +
  1.1336 + The pthread_condattr_init function initializes a condition attribute object with the default
  1.1337 +attributes.(As of now None)
  1.1338 +
  1.1339 + The pthread_condattr_destroy function destroys a condition attribute object.
  1.1340 +
  1.1341 +Examples:
  1.1342 +@code
  1.1343 + pthread_condattr_t condattr;
  1.1344 + int rc;
  1.1345 + /* Initialize a condition variable attributes object */
  1.1346 + if((rc=pthread_condattr_init(&condattr;)) != 0)
  1.1347 + {
  1.1348 +  fprintf(stderr,"Cannot initialize condition variable attributes object
  1.1349 +");
  1.1350 +  return -1;
  1.1351 + }
  1.1352 + /* Destroy the condition variable attributes object */
  1.1353 + if(pthread_condattr_destroy(&condattr;) != 0)
  1.1354 + {
  1.1355 +  fprintf(stderr,"Error at pthread_condattr_destroy(), rc=%d
  1.1356 +", rc);
  1.1357 +  return -1;
  1.1358 + }
  1.1359 +
  1.1360 +@endcode
  1.1361 +@see pthread_cond_init()
  1.1362 +
  1.1363 +
  1.1364 + 
  1.1365 +
  1.1366 +@publishedAll
  1.1367 +@externallyDefinedApi
  1.1368 +*/
  1.1369 +
  1.1370 +/** @fn  pthread_condattr_destroy(pthread_condattr_t *)
  1.1371 +
  1.1372 +Refer  pthread_condattr_init() for the documentation
  1.1373 +@see pthread_cond_init()
  1.1374 +
  1.1375 +
  1.1376 + 
  1.1377 +
  1.1378 +@publishedAll
  1.1379 +@externallyDefinedApi
  1.1380 +*/
  1.1381 +
  1.1382 +/** @fn  pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *)
  1.1383 +@param cond
  1.1384 +@param # represents the parameter attr
  1.1385 +@return   If successful, the pthread_cond_init function will return zero and put the new condition variable id into cond ,
  1.1386 +otherwise an error number will be returned to indicate the error.
  1.1387 +
  1.1388 +  The pthread_cond_init function creates a new condition variable referenced 
  1.1389 +by cond with attributes referenced by attr. If attr is NULL, the default condition variable attributes will be used. 
  1.1390 +Upon successful initialization, the state of the condition variable will be initialized.
  1.1391 +
  1.1392 +Examples:
  1.1393 +@code
  1.1394 +int rc;
  1.1395 +struct testdata
  1.1396 +{
  1.1397 + pthread_mutex_t mutex;
  1.1398 + pthread_cond_t  cond;
  1.1399 +};
  1.1400 +static struct testdata td;
  1.1401 +int function1()
  1.1402 +{
  1.1403 + /* Initialize a condition variable object */
  1.1404 + if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1.1405 +  fprintf(stderr,"Fail to initialize cond
  1.1406 +");
  1.1407 +  return -1;
  1.1408 + }
  1.1409 + /* ... Use it for wait, signal, broadcast */
  1.1410 + /* Destroy the condition variable object */
  1.1411 + if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1.1412 + {
  1.1413 +   fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1.1414 +",rc);
  1.1415 +   return -1;
  1.1416 + }
  1.1417 +}
  1.1418 +
  1.1419 +@endcode
  1.1420 +@see pthread_cond_broadcast()
  1.1421 +@see pthread_cond_destroy()
  1.1422 +@see pthread_cond_signal()
  1.1423 +@see pthread_cond_timedwait()
  1.1424 +@see pthread_cond_wait()
  1.1425 +
  1.1426 +
  1.1427 + 
  1.1428 +
  1.1429 +@publishedAll
  1.1430 +@externallyDefinedApi
  1.1431 +*/
  1.1432 +
  1.1433 +/** @fn  pthread_cond_destroy(pthread_cond_t *cond)
  1.1434 +@param cond
  1.1435 +@return   If successful, the pthread_cond_destroy function will return zero, otherwise an error number will be returned
  1.1436 +to indicate the error.
  1.1437 +
  1.1438 +  The pthread_cond_destroy function frees the resources allocated by the condition variable cond .
  1.1439 +
  1.1440 +Examples:
  1.1441 +@code
  1.1442 +int rc;
  1.1443 +struct testdata
  1.1444 +{
  1.1445 + pthread_mutex_t mutex;
  1.1446 + pthread_cond_t  cond;
  1.1447 +};
  1.1448 +static struct testdata td;
  1.1449 +int function1()
  1.1450 +{
  1.1451 + /* Initialize a condition variable object */
  1.1452 + if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1.1453 +  fprintf(stderr,"Fail to initialize cond
  1.1454 +");
  1.1455 +  return -1;
  1.1456 + }
  1.1457 + /* ... Use it for wait, signal, broadcast */
  1.1458 + /* Destroy the condition variable object */
  1.1459 + if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1.1460 + {
  1.1461 +   fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1.1462 +",rc);
  1.1463 +   return -1;
  1.1464 + }
  1.1465 +}
  1.1466 +
  1.1467 +@endcode
  1.1468 +@see pthread_cond_broadcast()
  1.1469 +@see pthread_cond_init()
  1.1470 +@see pthread_cond_signal()
  1.1471 +@see pthread_cond_timedwait()
  1.1472 +@see pthread_cond_wait()
  1.1473 +
  1.1474 +
  1.1475 + 
  1.1476 +
  1.1477 +@publishedAll
  1.1478 +@externallyDefinedApi
  1.1479 +*/
  1.1480 +
  1.1481 +/** @fn  pthread_cond_destroy(pthread_cond_t *cond)
  1.1482 +@param cond
  1.1483 +@return   If successful, the pthread_cond_destroy function will return zero, otherwise an error number will be returned
  1.1484 +to indicate the error.
  1.1485 +
  1.1486 +  The pthread_cond_destroy function frees the resources allocated by the condition variable cond .
  1.1487 +
  1.1488 +Examples:
  1.1489 +@code
  1.1490 +int rc;
  1.1491 +struct testdata
  1.1492 +{
  1.1493 + pthread_mutex_t mutex;
  1.1494 + pthread_cond_t  cond;
  1.1495 +};
  1.1496 +static struct testdata td;
  1.1497 +int function1()
  1.1498 +{
  1.1499 + /* Initialize a condition variable object */
  1.1500 + if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1.1501 +  fprintf(stderr,"Fail to initialize cond
  1.1502 +");
  1.1503 +  return -1;
  1.1504 + }
  1.1505 + /* ... Use it for wait, signal, broadcast */
  1.1506 + /* Destroy the condition variable object */
  1.1507 + if((rc=pthread_cond_destroy(&td.cond;)) != 0)
  1.1508 + {
  1.1509 +   fprintf(stderr,"Error at pthread_cond_destroy(), rc=%d
  1.1510 +",rc);
  1.1511 +   return -1;
  1.1512 + }
  1.1513 +}
  1.1514 +
  1.1515 +@endcode
  1.1516 +@see pthread_cond_broadcast()
  1.1517 +@see pthread_cond_init()
  1.1518 +@see pthread_cond_signal()
  1.1519 +@see pthread_cond_timedwait()
  1.1520 +@see pthread_cond_wait()
  1.1521 +
  1.1522 +
  1.1523 + 
  1.1524 +
  1.1525 +@publishedAll
  1.1526 +@externallyDefinedApi
  1.1527 +*/
  1.1528 +
  1.1529 +/** @fn  pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
  1.1530 +@param cond
  1.1531 +@param mutex
  1.1532 +@return   If successful, the pthread_cond_wait function will return zero.
  1.1533 +Otherwise an error number will be returned to
  1.1534 +indicate the error.
  1.1535 +
  1.1536 +  The pthread_cond_wait function atomically blocks the current thread waiting on the condition
  1.1537 +variable specified by cond ,
  1.1538 +and unblocks the mutex specified by mutex .
  1.1539 +The waiting thread unblocks only after another thread calls pthread_cond_signal ,
  1.1540 +or pthread_cond_broadcast with the same condition variable, and the current thread reacquires the lock
  1.1541 +on mutex .
  1.1542 +
  1.1543 +Examples:
  1.1544 +@code
  1.1545 +struct testdata
  1.1546 +{
  1.1547 + pthread_mutex_t mutex;
  1.1548 + pthread_cond_t  cond;
  1.1549 +};
  1.1550 +static struct testdata td;
  1.1551 +int rc;
  1.1552 +/* mutex and conditional variable must be initialized */
  1.1553 +if (pthread_mutex_lock(&td.mutex;) != 0) {
  1.1554 +  fprintf(stderr,"Thread failed to acquire mutex
  1.1555 +");
  1.1556 +  return -1;
  1.1557 + }
  1.1558 +fprintf(stderr,"Thread started
  1.1559 +");
  1.1560 +fprintf(stderr,"Thread is waiting for the cond
  1.1561 +");
  1.1562 +rc = pthread_cond_wait(&td.cond;, &td.mutex;);
  1.1563 +if (rc != 0) {
  1.1564 +  fprintf(stderr,"pthread_cond_wait return %d
  1.1565 +", rc);
  1.1566 +  return -1;
  1.1567 +}
  1.1568 +fprintf(stderr,"Thread wakened
  1.1569 +");
  1.1570 +pthread_mutex_unlock(&td.mutex;);
  1.1571 +
  1.1572 +@endcode
  1.1573 +@see pthread_cond_broadcast()
  1.1574 +@see pthread_cond_destroy()
  1.1575 +@see pthread_cond_init()
  1.1576 +@see pthread_cond_signal()
  1.1577 +@see pthread_cond_timedwait()
  1.1578 +
  1.1579 +
  1.1580 + 
  1.1581 +
  1.1582 +@publishedAll
  1.1583 +@externallyDefinedApi
  1.1584 +*/
  1.1585 +
  1.1586 +/** @fn  pthread_cond_signal(pthread_cond_t *cond)
  1.1587 +@param cond
  1.1588 +@return   If successful, the pthread_cond_signal function will return zero, otherwise an error number will be returned
  1.1589 +to indicate the error.
  1.1590 +
  1.1591 +  The pthread_cond_signal function unblocks one thread waiting for the condition variable cond .
  1.1592 +
  1.1593 +Examples:
  1.1594 +@code
  1.1595 + int rc;
  1.1596 +struct testdata
  1.1597 +{
  1.1598 + pthread_mutex_t mutex;
  1.1599 + pthread_cond_t  cond;
  1.1600 +};
  1.1601 +static struct testdata td;
  1.1602 +int function1()
  1.1603 +{
  1.1604 + if (pthread_mutex_init(&td.mutex;, NULL) != 0) {
  1.1605 +  fprintf(stderr,"Fail to initialize mutex
  1.1606 +");
  1.1607 +  return -1;
  1.1608 + }
  1.1609 + if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1.1610 +  fprintf(stderr,"Fail to initialize cond
  1.1611 +");
  1.1612 +  return -1;
  1.1613 + }
  1.1614 + /* ....... other thread wait for signal */
  1.1615 + /* Acquire the mutex to make sure that all waiters are currently 
  1.1616 +    blocked on pthread_cond_wait */
  1.1617 + if (pthread_mutex_lock(&td.mutex;) != 0) {
  1.1618 +  fprintf(stderr,"Main: Fail to acquire mutex
  1.1619 +");
  1.1620 +  return -1;
  1.1621 + }
  1.1622 + if (pthread_mutex_unlock(&td.mutex;) != 0) {
  1.1623 +  fprintf(stderr,"Main: Fail to release mutex
  1.1624 +");
  1.1625 +  return -1;
  1.1626 + }
  1.1627 + /* signal the condition to wake up all waiters */
  1.1628 + fprintf(stderr," signal the condition
  1.1629 +");
  1.1630 + rc = pthread_cond_signal(&td.cond;);
  1.1631 + if (rc != 0) {
  1.1632 +  fprintf(stderr," failed to signal the condition
  1.1633 +");
  1.1634 +  return -1;
  1.1635 + }
  1.1636 +}
  1.1637 +
  1.1638 +@endcode
  1.1639 +@see pthread_cond_broadcast()
  1.1640 +@see pthread_cond_destroy()
  1.1641 +@see pthread_cond_init()
  1.1642 +@see pthread_cond_timedwait()
  1.1643 +@see pthread_cond_wait()
  1.1644 +
  1.1645 +
  1.1646 + 
  1.1647 +
  1.1648 +@publishedAll
  1.1649 +@externallyDefinedApi
  1.1650 +*/
  1.1651 +
  1.1652 +/** @fn  pthread_cond_broadcast(pthread_cond_t *cond)
  1.1653 +@param cond
  1.1654 +@return   If successful, the pthread_cond_broadcast function will return zero, otherwise an error number will be returned
  1.1655 +to indicate the error.
  1.1656 +
  1.1657 +  The pthread_cond_broadcast function unblocks all threads waiting for the condition variable cond .
  1.1658 +
  1.1659 +Examples:
  1.1660 +@code
  1.1661 + int rc;
  1.1662 +struct testdata
  1.1663 +{
  1.1664 + pthread_mutex_t mutex;
  1.1665 + pthread_cond_t  cond;
  1.1666 +};
  1.1667 +static struct testdata td;
  1.1668 + if (pthread_mutex_init(&td.mutex;, NULL) != 0) {
  1.1669 +  fprintf(stderr,"Fail to initialize mutex
  1.1670 +");
  1.1671 +  return -1;
  1.1672 + }
  1.1673 + if (pthread_cond_init(&td.cond;, NULL) != 0) {
  1.1674 +  fprintf(stderr,"Fail to initialize cond
  1.1675 +");
  1.1676 +  return -1;
  1.1677 + }
  1.1678 +/* ....... other thread wait for signal */
  1.1679 + /* Acquire the mutex to make sure that all waiters are currently 
  1.1680 +    blocked on pthread_cond_wait */
  1.1681 + if (pthread_mutex_lock(&td.mutex;) != 0) {
  1.1682 +  fprintf(stderr,"Main: Fail to acquire mutex
  1.1683 +");
  1.1684 +  return -1;
  1.1685 + }
  1.1686 + if (pthread_mutex_unlock(&td.mutex;) != 0) {
  1.1687 +  fprintf(stderr,"Main: Fail to release mutex
  1.1688 +");
  1.1689 +  return -1;
  1.1690 + }
  1.1691 + /* signal the condition to wake up all waiters */
  1.1692 + fprintf(stderr," signal the condition0);
  1.1693 + rc = pthread_cond_broadcast(&td.cond;);
  1.1694 + if (rc != 0) {
  1.1695 +  fprintf(stderr," failed to signal the condition
  1.1696 +");
  1.1697 +  return -1;
  1.1698 + }
  1.1699 +
  1.1700 +@endcode
  1.1701 +@see pthread_cond_destroy()
  1.1702 +@see pthread_cond_init()
  1.1703 +@see pthread_cond_signal()
  1.1704 +@see pthread_cond_timedwait()
  1.1705 +@see pthread_cond_wait()
  1.1706 +
  1.1707 +
  1.1708 + 
  1.1709 +
  1.1710 +@publishedAll
  1.1711 +@externallyDefinedApi
  1.1712 +*/
  1.1713 +
  1.1714 +/** @fn  pthread_key_create(pthread_key_t *key, destructor_routine dest)
  1.1715 +@param key
  1.1716 +@param dest
  1.1717 +@return   If successful, the pthread_key_create function will store the newly created key value at the location specified by key and returns zero.
  1.1718 +Otherwise an error number will be returned to indicate
  1.1719 +the error.
  1.1720 +
  1.1721 +  The pthread_key_create function creates a thread-specific data key visible to all threads in the
  1.1722 +process.
  1.1723 +Key values provided by pthread_key_create are opaque objects used to locate thread-specific data.
  1.1724 +Although the same
  1.1725 +key value may be used by different threads, the values bound to the key
  1.1726 +by pthread_setspecific are maintained on a per-thread basis and persist for the life of the calling
  1.1727 +thread.
  1.1728 +
  1.1729 + Upon key creation, the value NULL is associated with the new key in all
  1.1730 +active threads.
  1.1731 +Upon thread creation, the value NULL is associated with all
  1.1732 +defined keys in the new thread.
  1.1733 +
  1.1734 + An optional destructor function dest may be associated with each key value.
  1.1735 +At
  1.1736 +thread exit, if a key value has a non-NULL destructor pointer, and the
  1.1737 +thread has a non-NULL value associated with the key, the function pointed
  1.1738 +to is called with the current associated value as its sole argument.
  1.1739 +The
  1.1740 +order of destructor calls is unspecified if more than one destructor exists
  1.1741 +for a thread when it exits.
  1.1742 +
  1.1743 + If, after all the destructors have been called for all non-NULL values
  1.1744 +with associated destructors, there are still some non-NULL values with
  1.1745 +associated destructors, then the process is repeated.
  1.1746 +If, after at least
  1.1747 +[PTHREAD_DESTRUCTOR_ITERATIONS] iterations of destructor calls for
  1.1748 +outstanding non-NULL values, there are still some non-NULL values with
  1.1749 +associated destructors, the implementation stops calling destructors.
  1.1750 +
  1.1751 +Examples:
  1.1752 +@code
  1.1753 +pthread_key_t keys;
  1.1754 +if(pthread_key_create(&keys;, NULL) != 0)
  1.1755 +{
  1.1756 +   printf("Error: pthread_key_create() failed
  1.1757 +");
  1.1758 +   return -1;
  1.1759 +}
  1.1760 +
  1.1761 +@endcode
  1.1762 +@see pthread_getspecific()
  1.1763 +@see pthread_key_delete()
  1.1764 +@see pthread_setspecific()
  1.1765 +
  1.1766 +
  1.1767 + 
  1.1768 +
  1.1769 +@publishedAll
  1.1770 +@externallyDefinedApi
  1.1771 +*/
  1.1772 +
  1.1773 +/** @fn  pthread_key_delete(pthread_key_t key)
  1.1774 +@param key
  1.1775 +@return   If successful, the pthread_key_delete function will return zero.
  1.1776 +Otherwise an error number will be returned to
  1.1777 +indicate the error.
  1.1778 +
  1.1779 +  The pthread_key_delete function deletes a thread-specific data key previously returned by pthread_key_create .
  1.1780 +The thread-specific data values associated with key need not be NULL at the time that pthread_key_delete is called.
  1.1781 +It is the responsibility of the application to free any
  1.1782 +application storage or perform any cleanup actions for data structures
  1.1783 +related to the deleted key or associated thread-specific data in any threads;
  1.1784 +this cleanup can be done either before or after pthread_key_delete is called.
  1.1785 +Any attempt to use key following the call to pthread_key_delete results in undefined behavior.
  1.1786 +
  1.1787 + The pthread_key_delete function is callable from within destructor functions.
  1.1788 +Destructor functions
  1.1789 +are not invoked by pthread_key_delete .
  1.1790 +Any destructor function that may have been associated with key will no longer be called upon thread exit.
  1.1791 +
  1.1792 +Examples:
  1.1793 +@code
  1.1794 +pthread_key_t keys;
  1.1795 +if(pthread_key_create(&keys;, NULL) != 0)
  1.1796 +{
  1.1797 +   printf("Error: pthread_key_create() failed
  1.1798 +");
  1.1799 +   return -1;
  1.1800 +}
  1.1801 +if(pthread_key_delete(keys) != 0)
  1.1802 +{
  1.1803 +  printf("Error: pthread_key_delete() failed
  1.1804 +");
  1.1805 +  return -1;  
  1.1806 +}
  1.1807 +
  1.1808 +@endcode
  1.1809 +@see pthread_getspecific()
  1.1810 +@see pthread_key_create()
  1.1811 +@see pthread_setspecific()
  1.1812 +
  1.1813 +
  1.1814 + 
  1.1815 +
  1.1816 +@publishedAll
  1.1817 +@externallyDefinedApi
  1.1818 +*/
  1.1819 +
  1.1820 +/** @fn  pthread_setspecific(pthread_key_t key, const void *value)
  1.1821 +@param key
  1.1822 +@param value
  1.1823 +@return   If successful, the pthread_setspecific function will return zero.
  1.1824 +Otherwise an error number will be returned to
  1.1825 +indicate the error.
  1.1826 +
  1.1827 +  The pthread_setspecific function associates a thread-specific value with a key obtained via a previous call to pthread_key_create .
  1.1828 +Different threads can bind different values to the same key.
  1.1829 +These values are
  1.1830 +typically pointers to blocks of dynamically allocated memory that have been
  1.1831 +reserved for use by the calling thread.
  1.1832 +
  1.1833 + 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.
  1.1834 +
  1.1835 + The pthread_setspecific function may be called from a thread-specific data destructor function,
  1.1836 +however this may result in lost storage or infinite loops.
  1.1837 +
  1.1838 +Examples:
  1.1839 +@code
  1.1840 + pthread_key_t keys;
  1.1841 + void* rc;
  1.1842 +if(pthread_key_create(&keys;, NULL) != 0)
  1.1843 +{
  1.1844 +   printf("Error: pthread_key_create() failed
  1.1845 +");
  1.1846 +   return -1;
  1.1847 +} else
  1.1848 +{
  1.1849 +   if(pthread_setspecific(keys, (void *)(long)(100)) != 0)
  1.1850 +   {
  1.1851 +    printf("Error: pthread_setspecific() failed
  1.1852 +");
  1.1853 +    return -1;
  1.1854 +   }
  1.1855 +}
  1.1856 +
  1.1857 +@endcode
  1.1858 +@see pthread_getspecific()
  1.1859 +@see pthread_key_create()
  1.1860 +@see pthread_key_delete()
  1.1861 +
  1.1862 +
  1.1863 + 
  1.1864 +
  1.1865 +@publishedAll
  1.1866 +@externallyDefinedApi
  1.1867 +*/
  1.1868 +
  1.1869 +/** @fn  pthread_getspecific(pthread_key_t key)
  1.1870 +@param key
  1.1871 +@return   The pthread_getspecific function will return the thread-specific data value associated with the given key .
  1.1872 +If no thread-specific data value is associated with key ,
  1.1873 +then the value NULL is returned.
  1.1874 +
  1.1875 +  The pthread_getspecific function returns the value currently bound to the specified key on behalf of the calling thread.
  1.1876 +
  1.1877 + 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.
  1.1878 +
  1.1879 + The pthread_getspecific function may be called from a thread-specific data destructor function.
  1.1880 +
  1.1881 +Examples:
  1.1882 +@code
  1.1883 +pthread_key_t keys;
  1.1884 + void* rc;
  1.1885 +if(pthread_key_create(&keys;, NULL) != 0)
  1.1886 +{
  1.1887 +   printf("Error: pthread_key_create() failed0);
  1.1888 +   return -1;
  1.1889 +} else
  1.1890 +{
  1.1891 +   if(pthread_setspecific(keys, (void *)(long)(100)) != 0)
  1.1892 +   {
  1.1893 +    printf("Error: pthread_setspecific() failed
  1.1894 +");
  1.1895 +    return -1;
  1.1896 +   }
  1.1897 +}
  1.1898 +rc = pthread_getspecific(keys);
  1.1899 +if(rc != (void *)(long)(100))
  1.1900 +{
  1.1901 +   printf("getspecific failed 
  1.1902 +");
  1.1903 +   return -1;
  1.1904 +}
  1.1905 +
  1.1906 +@endcode
  1.1907 +@see pthread_key_create()
  1.1908 +@see pthread_key_delete()
  1.1909 +@see pthread_setspecific()
  1.1910 +
  1.1911 +
  1.1912 + 
  1.1913 +
  1.1914 +@publishedAll
  1.1915 +@externallyDefinedApi
  1.1916 +*/
  1.1917 +
  1.1918 +/** @fn  pthread_attr_getscope(const pthread_attr_t *attrib, int *scope)
  1.1919 +@param attrib
  1.1920 +@param scope
  1.1921 +Refer  pthread_attr_init() for the documentation
  1.1922 +@see pthread_create()
  1.1923 +
  1.1924 +
  1.1925 + 
  1.1926 +
  1.1927 +@publishedAll
  1.1928 +@externallyDefinedApi
  1.1929 +*/
  1.1930 +
  1.1931 +/** @fn  pthread_attr_setscope(pthread_attr_t *attrib, int conscope)
  1.1932 +@param attrib
  1.1933 +@param conscope
  1.1934 +Refer  pthread_attr_init() for the documentation
  1.1935 +@see pthread_create()
  1.1936 +
  1.1937 +
  1.1938 + 
  1.1939 +
  1.1940 +@publishedAll
  1.1941 +@externallyDefinedApi
  1.1942 +*/
  1.1943 +
  1.1944 +/** @fn  pthread_attr_setschedpolicy(pthread_attr_t *attrib, int policy)
  1.1945 +@param attrib
  1.1946 +@param policy
  1.1947 +Refer  pthread_attr_init() for the documentation
  1.1948 +@see pthread_create()
  1.1949 +
  1.1950 +
  1.1951 + 
  1.1952 +
  1.1953 +@publishedAll
  1.1954 +@externallyDefinedApi
  1.1955 +*/
  1.1956 +
  1.1957 +/** @fn  pthread_attr_getschedpolicy(const pthread_attr_t *attrib, int *policy)
  1.1958 +@param attrib
  1.1959 +@param policy
  1.1960 +Refer  pthread_attr_init() for the documentation
  1.1961 +@see pthread_create()
  1.1962 +
  1.1963 +
  1.1964 + 
  1.1965 +
  1.1966 +@publishedAll
  1.1967 +@externallyDefinedApi
  1.1968 +*/
  1.1969 +
  1.1970 +/** @fn  pthread_attr_getschedparam(const pthread_attr_t *attrib, struct sched_param *param)
  1.1971 +@param attrib
  1.1972 +@param param
  1.1973 +Refer  pthread_attr_init() for the documentation
  1.1974 +@see pthread_create()
  1.1975 +
  1.1976 +
  1.1977 + 
  1.1978 +
  1.1979 +@publishedAll
  1.1980 +@externallyDefinedApi
  1.1981 +*/
  1.1982 +
  1.1983 +/** @fn  pthread_attr_setschedparam(pthread_attr_t *attrib, const struct sched_param *param)
  1.1984 +@param attrib
  1.1985 +@param param
  1.1986 +Refer  pthread_attr_init() for the documentation
  1.1987 +@see pthread_create()
  1.1988 +
  1.1989 +
  1.1990 + 
  1.1991 +
  1.1992 +@publishedAll
  1.1993 +@externallyDefinedApi
  1.1994 +*/          
  1.1995 +                           
  1.1996 +/** @fn  pthread_getschedparam(pthread_t thr, int *policy, struct sched_param *param)
  1.1997 +@param thr
  1.1998 +@param policy
  1.1999 +@param param
  1.2000 +Refer  pthread_setschedparam() for the documentation
  1.2001 +
  1.2002 +
  1.2003 + 
  1.2004 +
  1.2005 +@publishedAll
  1.2006 +@externallyDefinedApi
  1.2007 +*/  
  1.2008 +                                      
  1.2009 +/** @fn  pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
  1.2010 +@param thread
  1.2011 +@param policy
  1.2012 +@param param
  1.2013 +Note: This description also covers the following functions -
  1.2014 + pthread_getschedparam() 
  1.2015 +
  1.2016 +@return   If successful, these functions return 0.
  1.2017 +Otherwise, an error number is returned to indicate the error.
  1.2018 +
  1.2019 +  The pthread_setschedparam and pthread_getschedparam functions set and get the scheduling parameters of individual threads.
  1.2020 +The scheduling policy for a thread will be SCHED_RR (round-robin). ( SCHED_FIFO is not supported)
  1.2021 +The thread priority (accessed via param-\>sched_priority )
  1.2022 +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) .
  1.2023 +
  1.2024 +Examples:
  1.2025 +@code
  1.2026 +struct sched_param sparam;
  1.2027 +int policy, priority, policy_1;
  1.2028 +int rc;
  1.2029 +policy = SCHED_RR;
  1.2030 +priority = 50;
  1.2031 +sparam.sched_priority = priority;
  1.2032 +rc = pthread_setschedparam(pthread_self(), policy, &sparam;);
  1.2033 +if (rc != 0)
  1.2034 +{
  1.2035 +  printf("Error at pthread_setschedparam: rc=%d
  1.2036 +", rc);
  1.2037 +  return -1;
  1.2038 +}
  1.2039 +
  1.2040 +@endcode
  1.2041 +@code
  1.2042 +int e ;
  1.2043 +struct sched_param param;
  1.2044 +pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
  1.2045 +pthread_t thread = pthread_self();
  1.2046 +param.sched_priority = 100;
  1.2047 + 
  1.2048 +e = pthread_setschedparam(thread,SCHED_RR, & param);
  1.2049 +if(e != 0)
  1.2050 +{
  1.2051 +   printf("setting scheduling policy and priority failed."));
  1.2052 +   return -1;
  1.2053 +}
  1.2054 +
  1.2055 +@endcode
  1.2056 +@code
  1.2057 +int e ;
  1.2058 +struct sched_param param;
  1.2059 +pthread_t thread; // Thread which will be assigned the scheduling priority and the policy.
  1.2060 +int policy;
  1.2061 +pthread_t thread = pthread_self();
  1.2062 +param.sched_priority = 100;
  1.2063 + 
  1.2064 +e = pthread_setschedparam(thread,SCHED_RR, & param);
  1.2065 +if(e != 0)
  1.2066 +{
  1.2067 +   printf("setting scheduling policy and priority failed."));
  1.2068 +   return -1;
  1.2069 +}
  1.2070 +e = pthread_getschedparam(thread,&policy;,& param);
  1.2071 +if (e != 0)
  1.2072 +{
  1.2073 +   printf("getting scheduling policy and priority failed."));
  1.2074 +   return -1;
  1.2075 +}
  1.2076 +
  1.2077 +@endcode
  1.2078 + 
  1.2079 +
  1.2080 +@publishedAll
  1.2081 +@externallyDefinedApi
  1.2082 +*/                                   
  1.2083 +
  1.2084 +
  1.2085 +/** @fn  pthread_cond_timedwait(pthread_cond_t * cond,pthread_mutex_t * mutex,const struct timespec *abstime)
  1.2086 +@param cond
  1.2087 +@param mutex
  1.2088 +@param abstime
  1.2089 +@return   If successful, the pthread_cond_timedwait function will return zero.
  1.2090 +Otherwise an error number will be returned to
  1.2091 +indicate the error.
  1.2092 +
  1.2093 +  The pthread_cond_timedwait function atomically blocks the current thread waiting on the condition,
  1.2094 +specified by the cond,and unblocks the mutex specified by the mutex.
  1.2095 +
  1.2096 + The waiting thread unblocks only after another thread calls pthread_cond_signal,pthread_cond_broadcast with the same condition variable,
  1.2097 +or if the system time reaches the time specified in abstime,and the current thread reacquires the lock on the mutex.
  1.2098 +
  1.2099 +
  1.2100 +
  1.2101 +Examples:
  1.2102 +@code
  1.2103 +struct testdata
  1.2104 +{
  1.2105 +pthread_mutex mutex;
  1.2106 +pthread_cond_t cond;
  1.2107 +};
  1.2108 +static struct testdata td;
  1.2109 +int rc;
  1.2110 +struct timespec timeout;
  1.2111 +struct timeval curtime;
  1.2112 +if(pthread_mutex_lock(&td.mutex)!=0)
  1.2113 +  {
  1.2114 +  fprintf(stderr,"fail");
  1.2115 +  return -1;
  1.2116 +  }
  1.2117 +if(gettimeofday(&curtime,NULL)!=0)
  1.2118 +  {
  1.2119 +  fprintf(stderr,"fail");
  1.2120 +  return -1;
  1.2121 +  }
  1.2122 +timeout.tv_sec=curtime.tv_sec;
  1.2123 +timeout.tv_nsec=curtime.tv_nsec;
  1.2124 +timeout.tv_sec+=TIMEOUT;
  1.2125 +fprintf(stderr,"thread is waiting on the cond");
  1.2126 +rc=pthread_cond_timedwait(&td.cond,&td.mutex,&timeout);
  1.2127 +if(rc!=0)
  1.2128 +  {
  1.2129 +  if(rc==ETIMEDOUT)
  1.2130 +    {
  1.2131 +    fprintf(stderr,"thread stops when time is out");
  1.2132 +    return -1;
  1.2133 +    }
  1.2134 +  else
  1.2135 +   {
  1.2136 +   fprintf(stderr,"pthread_cond_timedwait return");
  1.2137 +   return -1;
  1.2138 +   }
  1.2139 +  }
  1.2140 +fprintf(stderr,"thread wakened up");
  1.2141 +pthread_mutex_unlock(&td.mutex);
  1.2142 +@endcode
  1.2143 +@see pthread_exit()
  1.2144 +@see pthread_join()
  1.2145 +
  1.2146 +
  1.2147 + 
  1.2148 +
  1.2149 +@publishedAll
  1.2150 +@externallyDefinedApi
  1.2151 +*/