public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* Re: [ECOS] Nested calls to Mutexes
@ 2001-03-21  6:54 Rosimildo daSilva
  0 siblings, 0 replies; 11+ messages in thread
From: Rosimildo daSilva @ 2001-03-21  6:54 UTC (permalink / raw)
  To: ecos-discuss

>From: Andrew Lunn <andrew.lunn@ascom.ch>
>To: eCos Disuss <ecos-discuss@sourceware.cygnus.com>
>Subject: Re: [ECOS] Nested calls to Mutexes
>Date: Wed, 21 Mar 2001 14:59:08 +0100
>To me this is dangerous. Mutex's are used to protect state
>information. I lock the mutex when im want to modify the state
>information. The locked mutex indicates the state information may not
>be consitent.

I am NOT going to argue with you. I believe that implementations
such as WIN32, OS/2, pSOS, RTEMS and many other OS provides have
a better semantic that the one that eCOs provides.

As long as the mutexes primitives guarantee that the mutex
still owned by the calling thread until all acquire()/release()
balance, I fail to see how this is dangerous.

If you plan to write code that must run on many platforms,
or at least you plan test a *fair amount* of your code on
platforms such as Lunix/Windows, it is nice to have the
mutex with the same behavior ( semantic ) of all OS's.
eCOs does not provide that for me, and I have to that
semantic to my code myself, possibly introducing errors.

Look at the behavior of the "synchronized" keyword of
java. It allows nested calls. There is no dangerous
doing this.

Show me a case where this behavior is dangerous ?

Rosimildo.








_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [ECOS] Nested calls to Mutexes
@ 2001-04-04 18:29 Rosimildo daSilva
  0 siblings, 0 replies; 11+ messages in thread
From: Rosimildo daSilva @ 2001-04-04 18:29 UTC (permalink / raw)
  To: ecos-discuss

>From: martin@fatbob.nu
>
>Well, this isn't entirely true. The default behaviour is as you describe, 
>but
>this can be changed using pthread_mutexattr_setkind_np(attr, kind)
>where kind can take the value PTHREAD_MUTEX_RECURSIVE_NP to create 
>recursive
>mutexes (reading from the man page for pthread_mutexattr_setkind_np(3)
>contained in glibc 2.2).
>I've run across this before, but it's easy to solve using some wrapper
>function to create recursive mutexes.
>
>Regards
>/Martin
>

Thanks Martin. This is very useful information.

Rosimildo.



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [ECOS] Nested calls to Mutexes
@ 2001-03-21  6:06 Rosimildo daSilva
  0 siblings, 0 replies; 11+ messages in thread
From: Rosimildo daSilva @ 2001-03-21  6:06 UTC (permalink / raw)
  To: ecos-discuss

>From: Bart Veer Reply-To: bartv@redhat.com To: rosimildo@hotmail.com CC: 
>ecos-discuss@sourceware.cygnus.com Subject: Re: [ECOS] Nested calls to 
>Mutexes Date: Wed, 21 Mar 2001 13:29:28 GMT
>
>
>This issue has been raised before. See e.g. 
> http://sources.redhat.com/ml/ecos-discuss/2000-06/msg00333.html and 
> http://sources.redhat.com/ml/ecos-discuss/2000-08/msg00061.html
>
>There are no plans to change eCos' behaviour in this respect.


Thanks.

Fair enough. I guess I have to add some wrapper class
to extend the Mutex behavior a bit, on my project.

Rosimildo.




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [ECOS] Nested calls to Mutexes
@ 2001-03-21  5:18 Rosimildo daSilva
  2001-03-21  5:29 ` Bart Veer
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Rosimildo daSilva @ 2001-03-21  5:18 UTC (permalink / raw)
  To: ecos-discuss

Hi, the project I am working on, we have faced a small problem
with mutexes.

From ecos documentation:

"When a thread locks a mutex it becomes the owner. Only the mutex's
owner
may unlock it. While a mutex remains locked, the owner should not lock
it
again, as the behavior is undefined and probably dangerous. "


I disagree with this statement. It is a *common idiom* to
have routines that needs to "lock" some access to start
calling other routines that "locks" the mutex again.
In any sizeable project, this happens eventually.
As long as the acquire()/release() calls are balanced,
it should be no problem.

  class A
  {
    public:

     void setData()
     {
        m.lock();
        // set some important data
        m.unlock();
     }


     void anotherMehod()
     {
        m.lock();

        // do some atomic operations here.

        if( ok )
        {
          setData();
        }

        // continue atomic operation

        m.unlock();
     }


   private:

    Mutex m;
  }


Many implementations out there support the concept of
nested/balanced mutex calls. That is the programmer's
expectation. Sorry, to put this way, but I consider
this a *bug*.

Rosimildo.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

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

end of thread, other threads:[~2001-04-04 18:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-21  6:54 [ECOS] Nested calls to Mutexes Rosimildo daSilva
  -- strict thread matches above, loose matches on Subject: below --
2001-04-04 18:29 Rosimildo daSilva
2001-03-21  6:06 Rosimildo daSilva
2001-03-21  5:18 Rosimildo daSilva
2001-03-21  5:29 ` Bart Veer
2001-03-21  5:42 ` Jonathan Larmour
2001-03-21  6:26   ` Andrew Lunn
2001-03-21  6:45     ` Lewin A.R.W. Edwards
2001-03-22  8:46 ` Jonathan Larmour
2001-04-04  8:08   ` martin
2001-04-04  8:17     ` Jonathan Larmour

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