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
pthread_suspend_np
pthread_resume_np 

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.

http://www.dslreports.com/forum/r19082719-FreeBSD-libthr-libpthread

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) {
        pthread_mutex_lock(&suspend_mutex);
        while (ready_to_go == 0) {
               pthread_cond_wait(&suspend_cond, &suspend_mutex);
        }
        pthread_mutex_unlock(&suspend_mutex);
        /* Now do our thing */
        ...
        return NULL;
}

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

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

        /* Do some stuff */
        ...
        /* Now tell thread to continue */
        pthread_mutex_lock(&suspend_mutex);
        ready_to_go = 1;
        pthread_mutex_unlock(&suspend_mutex);
        pthread_cond_signal(&suspend_cond);
}

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  http://vger.kernel.org/majordomo-info.html

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

  Powered by Linux