Non Portable pthread (-np) API for thread creation in suspend mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Dear All,

I have implemented a threading program using the pthread library on CentOS - 5.2 Linux system. (The CentOS is an Enterprise Linux distribution based on the freely available sources from Red Hat Enterprise Linux.) However, I need to create a pthread that is initially suspended. But, I did not find any API in the pthread library which does the my requirement. So, I googled and found some of the FreeBSD thread API which is as follows.


pthread_attr_setcreatesuspend_np  - prepare attribute for creation of suspended thread. I have also seen that the "_np" stands for "non portable" API. (The functions with the pthread_ prefix and _np suffix are not portable extensions to POSIX threads.)

My question is, how can I use the "_np" API on my Linux box. I guess, the "_np" API is available in "libthr" shared library. So, I tried to download the "libthr" shared library, but there is no luck to me. 

I have also one more question, Shall I use the "libthr" shared library on my CENTOS without affecting the "libpthread" library. If possible, please suggest me.

I can also able to implement the suspend and resume functionality with the following mechanism. But I have also seen that with "libthr" we get better performance than "libpthread". Please look at the following link. That is the reason, I want to use the "libthr" on my CENTOS Linux box.

static int ready_to_go = 0;
static pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;

static void *func(void *arg) {
        while (ready_to_go == 0) {
               pthread_cond_wait(&suspend_cond, &suspend_mutex);
        /* Now do our thing */
        return NULL;

void spawn_thread(void) {
        pthread_attr_t attr;
        pthread_t thread;

        /* We don't need to join this thread */
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
        pthread_create(&thread, &attr, func, NULL);

        /* Do some stuff */
        /* Now tell thread to continue */
        ready_to_go = 1;

Thanks in advance.

With Regards,
Srinivas G

To unsubscribe from this list: send the line "unsubscribe linux-gcc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Index of Archives]     [Kernel]     [Linux ARM]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux