pthread_getcpuclockid()

Return the clock ID of the CPU-time clock from a specified thread

Synopsis:

#include <sys/types.h>
#include <time.h>
#include <pthread.h>

int pthread_getcpuclockid( pthread_t id,
                           clockid_t* clock_id);

Arguments:

thread
The ID of the thread that you want to get the clock ID for, which you can get when you call pthread_create() or pthread_self().
clock_id
A pointer to a clockid_t object where the function can store the clock ID.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The pthread_getcpuclockid() function gets the clock ID of the CPU-time clock of the thread specified by id (if the thread exists) and stores the clock ID in the object that clock_id points to. The CPU-time clock represents the approximate amount of time that the thread has spent running. For more information, see Monitoring execution times in the Tick, Tock: Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide.

Returns:

0
Success.
ESRCH
The value specified by id doesn't refer to an existing thread.

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <pthread.h>

int main( int argc, const char *argv[] )
{
    clockid_t clk_id;
    struct timespec tspec;
    pthread_t tid;

    tid = pthread_self();

    if (pthread_getcpuclockid( tid, &clk_id) == 0)
    {
        if (clock_gettime( clk_id, &tspec ) != 0)
        {
            perror ("clock_gettime():");
        }
        else
        {
            printf ("CPU time for tid %d is %d seconds, %ld nanoseconds.\n",
                    tid, tspec.tv_sec, tspec.tv_nsec);
        }
    }
    else
    {
        printf ("pthread_getcpuclockid(): no thread with ID %d.\n", tid);
    }

    return EXIT_SUCCESS;
}

Classification:

POSIX 1003.1 THR TCT

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

clock_getcpuclockid(), clock_getres(), clock_gettime(), clock_settime(), ClockId(), ClockTime(), timer_create()

Clocks, Timers, and Getting a Kick Every So Often chapter of Getting Started with QNX Neutrino

Monitoring execution times in the Tick, Tock: Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide.