linux-gcc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Srinivas G." <srinivasg@esntechnologies.co.in>
To: linux-c-programming@vger.kernel.org, linux-apps@vger.kernel.org,
	linux-gcc@vger.kernel.org
Cc: Glynn Clements <glynn@gclements.plus.com>,
	bert.wesarg@googlemail.com, Richard Dengler <rdengler@arcor.de>,
	pradeep.rautela@gmail.com, uday.karan@gmail.com, brouits@free.fr,
	Manish Katiyar <mkatiyar@gmail.com>
Subject: Non Portable pthread (-np) API for thread creation in suspend mode
Date: Tue, 17 Mar 2009 18:26:18 +0530	[thread overview]
Message-ID: <F5BA82141F7AA94885B9643C77EEA5F2134DFA@mail.esntechnologies.co.in> (raw)

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

                 reply	other threads:[~2009-03-17 12:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F5BA82141F7AA94885B9643C77EEA5F2134DFA@mail.esntechnologies.co.in \
    --to=srinivasg@esntechnologies.co.in \
    --cc=bert.wesarg@googlemail.com \
    --cc=brouits@free.fr \
    --cc=glynn@gclements.plus.com \
    --cc=linux-apps@vger.kernel.org \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=linux-gcc@vger.kernel.org \
    --cc=mkatiyar@gmail.com \
    --cc=pradeep.rautela@gmail.com \
    --cc=rdengler@arcor.de \
    --cc=uday.karan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).