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

"Srinivas G." <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming,org.kernel.vger.linux-gcc
Message-ID <F5BA82141F7AA94885B9643C77EEA5F2134DFA@mail.esntechnologies.co.in>
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-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.