kern/43887: abnormal CPU useage when use pthread_mutex

Craig Rodrigues rodrigc at crodrigues.org
Mon Feb 2 14:10:49 PST 2004


The following reply was made to PR kern/43887; it has been noted by GNATS.

From: Craig Rodrigues <rodrigc at crodrigues.org>
To: freebsd-gnats-submit at freebsd.org
Cc: t_fisher at 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 at crodrigues.org


More information about the freebsd-threads mailing list