This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread_init_mutex problem




hi pankaj,
      thnx for your Input...i found that your code was not taking much of
CPU after introducing a sleep for once mili sec.
i have a different scene here..i have multiple threads trying to do the
same operations as what your main does.
Please have a look at this and give me your suggestions

#include "pthread.h"
#include <assert.h>

int main()
{
     CreateThread(NULL,0,mythread1,"Thread1",0,&thrId1);
     CreateThread(NULL,0,mythread1,"Thread2",0,&thrId2);

     for(;;)
     {
          Sleep(1);
     }
  return 0;
}

DWORD WINAPI mythread1(void*ptr)
{
     int i=0;
for(i = 0; i != 1000000; i++)
     {

          pthread_mutex_t mutex;
          assert(pthread_mutex_init(&mutex, NULL) == 0);
          assert(mutex != NULL);

          assert(pthread_mutex_lock(&mutex) == 0);
          printf("Locked:%s\n",(char*)ptr);
          Sleep(1);
          assert(pthread_mutex_unlock(&mutex) == 0);
          printf("UnLocked\n");
          assert(pthread_mutex_destroy(&mutex)==0);
          printf("Destroy\n");
     }
}

regds & thnx
srikanth




pankaj bathwal <pbathwal@yahoo.com> on 05/04/2002 10:53:46 AM

To:   Srikanth Sundaragopalan/HSSBLR
cc:

Subject:  Re: pthread_init_mutex problem




hi,
i think problem is not in the pthread_mutex_init
i have tried the below code and cpu never goes above
15%.....
Use debugger to find if problem is really in the
pthread_mutex_init


#include "pthread.h"
#include <assert.h>




int main()
{

     for(int i = 0; i != 100; i++)
     {

          pthread_mutex_t mutex;
          assert(pthread_mutex_init(&mutex, NULL) == 0);
          assert(mutex != NULL);
          assert(pthread_mutex_lock(&mutex) == 0);
          assert(pthread_mutex_unlock(&mutex) == 0);
     }

  return 0;
}


cheers
pankaj




--- ssundaragopalan@hss.hns.com wrote:
>
>
> hi all,
>         i am new to this mailing list. i am using
> pthreads for windows and
> have the following problems.
> The function pthread_mutex_init is taking up CPU to
> a large extent....In
> our program we have a lock for each data structure
> and this data struture
> is initialized every time a new messsage is
> received. So under Load
> conditions the CPU utilization is reaching 100%.
> Can anyone suggest some ways to bring down this.
>
> regds,
> srikanth
>
>
>
>
>
>
> This message is proprietary to Hughes Software
> Systems Limited (HSS) and is
> intended solely for the use of the individual to
> whom it is addressed.  It
> may contain privileged or confidential information
> and should not be
> circulated or used for any purpose other than for
> what it is intended.  If
> you have received this message in error, please
> notify the originator
> immediately.  If you are not the intended recipient,
> you are notified that
> you are strictly prohibited from using, copying,
> altering, or disclosing
> the contents of this message.  HSS accepts no
> responsibility for loss or
> damage arising from the use of the information
> transmitted by this email
> including damage from virus.
>
>


__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]