public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Re: pthread_init_mutex problem
@ 2002-05-04  4:19 ssundaragopalan
  0 siblings, 0 replies; 7+ messages in thread
From: ssundaragopalan @ 2002-05-04  4:19 UTC (permalink / raw)
  To: pankaj bathwal; +Cc: pthreads-win32



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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pthread_init_mutex problem
  2002-05-06  7:16 ssundaragopalan
@ 2002-05-06 20:53 ` Phil Frisbie, Jr.
  0 siblings, 0 replies; 7+ messages in thread
From: Phil Frisbie, Jr. @ 2002-05-06 20:53 UTC (permalink / raw)
  To: ssundaragopalan; +Cc: 5qduh001, pthreads-win32

ssundaragopalan@hss.hns.com wrote:
> 
> hi ppl,
>        thnx for your valuble inputs. ..actually i have implmented critical
> section as a solution and it works fine...the CPU utilization has come down
> to 60% from 100%...

That is just bandaging your design problem...

> thnx & regds,
> srikanth


Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pthread_init_mutex problem
@ 2002-05-06  7:16 ssundaragopalan
  2002-05-06 20:53 ` Phil Frisbie, Jr.
  0 siblings, 1 reply; 7+ messages in thread
From: ssundaragopalan @ 2002-05-06  7:16 UTC (permalink / raw)
  To: 5qduh001; +Cc: pthreads-win32



hi ppl,
       thnx for your valuble inputs. ..actually i have implmented critical
section as a solution and it works fine...the CPU utilization has come down
to 60% from 100%...

thnx & regds,
srikanth




5qduh001@sneakemail.com on 05/04/2002 02:42:43 PM

To:   Srikanth Sundaragopalan/HSSBLR, pthreads-win32@sources.redhat.com
cc:

Subject:  Re: pthread_init_mutex problem




I'd be interested in measurements comparing calling pthread_mutex_init()
vs. using PTHREAD_MUTEX_INITIALIZER.

I.e the code from the earlier e-mail:
pthread_mutex_t mutex;
assert(pthread_mutex_init(&mutex, NULL) == 0);

vs.

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

I haven't looked at the win32 pthread source to see what happens in either,
but I can only imagine that the latter would be more efficient if the
implementation in win32 pthreads is anything like what most other
implementations do (a linux implementation in this case), basically:

pthread_mutex_t mutex = {0, 0, 0, PTHREAD_MUTEX_FAST_NP, {0, 0}};

As I understand it, using PTHREAD_MUTEX_INITIALIZER should also allow you
to avoid the call to pthread_mutex_destroy() thus another saving.

If the PTHREAD_MUTEX_INITIALIZER is faster as I suspect, please let us know
and by roughly how much :).

Good luck,
Dave

-----------------------------------------------------
Protect yourself from spam, use http://sneakemail.com




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pthread_init_mutex problem
  2002-05-04  0:09 ssundaragopalan
@ 2002-05-04 11:28 ` Phil Frisbie, Jr.
  0 siblings, 0 replies; 7+ messages in thread
From: Phil Frisbie, Jr. @ 2002-05-04 11:28 UTC (permalink / raw)
  To: ssundaragopalan; +Cc: pthreads-win32

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.

You can reuse your data structure. I am already doing this in my HawkNL
network library for the internal socket structures. The socket structure
includes 2 mutexes. When I 'free' a socket, the structure in marked as
free, and the mutexes are reused when I need a new socket.

> regds,
> srikanth


Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: pthread_init_mutex problem
@ 2002-05-04 10:42 5qduh001
  0 siblings, 0 replies; 7+ messages in thread
From: 5qduh001 @ 2002-05-04 10:42 UTC (permalink / raw)
  To: ssundaragopalan, pthreads-win32

I'd be interested in measurements comparing calling pthread_mutex_init() vs. using PTHREAD_MUTEX_INITIALIZER.

I.e the code from the earlier e-mail:
pthread_mutex_t mutex;
assert(pthread_mutex_init(&mutex, NULL) == 0);

vs.

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

I haven't looked at the win32 pthread source to see what happens in either, but I can only imagine that the latter would be more efficient if the implementation in win32 pthreads is anything like what most other implementations do (a linux implementation in this case), basically:

pthread_mutex_t mutex = {0, 0, 0, PTHREAD_MUTEX_FAST_NP, {0, 0}};

As I understand it, using PTHREAD_MUTEX_INITIALIZER should also allow you to avoid the call to pthread_mutex_destroy() thus another saving.

If the PTHREAD_MUTEX_INITIALIZER is faster as I suspect, please let us know and by roughly how much :).

Good luck,
Dave

-----------------------------------------------------
Protect yourself from spam, use http://sneakemail.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: pthread_init_mutex problem
@ 2002-05-04 10:01 Eli Ofenstein
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Ofenstein @ 2002-05-04 10:01 UTC (permalink / raw)
  To: 'ssundaragopalan@hss.hns.com', pthreads-win32


Hi

In general, sync primitives as data structures aren't really meant to be
transient.  A high cost at init time is not uncommon.  In terms of
protecting data that is transient, perhaps a scheme for reusing the
data structures would be in order.  Something like maintaining a linklist,
or, even better, per-thread linklists on a TLS key.  Of course, this assumes
near-identical produce and consume rates.

> -----Original Message-----
> From: ssundaragopalan@hss.hns.com [mailto:ssundaragopalan@hss.hns.com]
> Sent: Saturday, May 04, 2002 2:08 AM
> To: pthreads-win32@sources.redhat.com
> Subject: pthread_init_mutex problem
> 
> 
> 
> 
> 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.
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* pthread_init_mutex problem
@ 2002-05-04  0:09 ssundaragopalan
  2002-05-04 11:28 ` Phil Frisbie, Jr.
  0 siblings, 1 reply; 7+ messages in thread
From: ssundaragopalan @ 2002-05-04  0:09 UTC (permalink / raw)
  To: pthreads-win32



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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-05-07  3:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-04  4:19 pthread_init_mutex problem ssundaragopalan
  -- strict thread matches above, loose matches on Subject: below --
2002-05-06  7:16 ssundaragopalan
2002-05-06 20:53 ` Phil Frisbie, Jr.
2002-05-04 10:42 5qduh001
2002-05-04 10:01 Eli Ofenstein
2002-05-04  0:09 ssundaragopalan
2002-05-04 11:28 ` Phil Frisbie, Jr.

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).