Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Feb 2004 14:10:19 -0800 (PST)
From:      Craig Rodrigues <rodrigc@crodrigues.org>
To:        freebsd-threads@FreeBSD.org
Subject:   Re: kern/43887: abnormal CPU useage when use pthread_mutex
Message-ID:  <200402022210.i12MAJx4057870@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/43887; it has been noted by GNATS.

From: Craig Rodrigues <rodrigc@crodrigues.org>
To: freebsd-gnats-submit@freebsd.org
Cc: t_fisher@163.com
Subject: Re: kern/43887: abnormal CPU useage when use pthread_mutex
Date: Mon, 2 Feb 2004 17:05:28 -0500

 Hi,
 
 I don't think that this PR is very meaningful, and should be closed.
 
 This PR basically complains about the following code
 consuming too much CPU if you take out the usleep().
 
 =====================================================================
 #include <unistd.h>
 #include <pthread.h>
 #include <errno.h>
 
 int main(int argc,char** argv)
 {
     pthread_mutex_t mutex;
     long i,j;
     j =0;
     pthread_mutex_init(&mutex,NULL);
     while(1)
     {
         pthread_mutex_lock(&mutex);
         i = j*j;
         j++;
         pthread_mutex_unlock(&mutex);
 
         printf("i=%ld\n",i);
         if(usleep(800)== -1)
             printf("usleep fail. %s",strerror(errno));
     }
     return 0;
 }
 =====================================================================
 
 Well, this code isn't doing too much, except for spinning
 in a tight loop.  I think this PR should be closed. 
 
 
 -- 
 Craig Rodrigues        
 rodrigc@crodrigues.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200402022210.i12MAJx4057870>