[omniORB] omniORB, posix rwlock_t and deadlock

Attila Pletyak attila.pletyak@anemo.com
Tue, 12 Jun 2001 14:38:38 +0200


--------------030307040507050500030009
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii; format=flowed



Dmitry Mityugov wrote:

>Just a shot in the dark.
>
>>   There is a wrapper class around the pthread_rwlock_t types, so they 
>>get unlocked in every case.
>>
>
>Have you defined a copy constructor and assignment operator for this class?
>
It looks like this:

class ReadWriteLock {
   pthread_rwlock_t &mutex;

public:
  enum LockType{
   READLOCK,
   WRITELOCK
  };

  ReadWriteLock (pthread_rwlock_t &m, LockType lt)
   : mutex (m)
  {
   
    switch (lt)
     {
   case READLOCK:
       default:
     pthread_rwlock_rdlock (&mutex);
     break;
       case WRITELOCK:
     pthread_rwlock_wrlock (&mutex);
     break;
     }

  }

  ~ReadWriteLock()
  {
    pthread_rwlock_unlock (&mutex);
  }
};

Every servant has an own pthread_rwlock_t member, which is initialized 
in its constructor, and before accessing the shared memory, there is a
ReadWriteLock currentRead( servantRWMember, ReadWriteLock::READLOCK );

Maybe my terminology is not correct as this is a helper class.

Attila Pletyak

>
>Dmitry
>
>
>


--------------030307040507050500030009
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset=us-ascii

<html><head></head><body><br>
<br>
Dmitry Mityugov wrote:<br>
<blockquote type="cite" cite="mid:008301c0f33b$2e9bb3f0$0100000a@ddhome"><pre wrap="">Just a shot in the dark.<br><br></pre>
  <blockquote type="cite"><pre wrap="">   There is a wrapper class around the pthread_rwlock_t types, so they <br>get unlocked in every case.<br></pre></blockquote>
    <pre wrap=""><!----><br>Have you defined a copy constructor and assignment operator for this class?<br></pre>
    </blockquote>
It looks like this:<br>
    <br>
class ReadWriteLock {<br>
 &nbsp;&nbsp; pthread_rwlock_t &amp;mutex;<br>
    <br>
public:<br>
&nbsp; enum LockType{<br>
 &nbsp;&nbsp; READLOCK,<br>
 &nbsp;&nbsp; WRITELOCK<br>
&nbsp; };<br>
    <br>
&nbsp; ReadWriteLock (pthread_rwlock_t &amp;m, LockType lt)<br>
 &nbsp;&nbsp; : mutex (m)<br>
 &nbsp; {<br>
 &nbsp; &nbsp; <br>
 &nbsp; &nbsp; switch (lt)<br>
 &nbsp;&nbsp; &nbsp; {<br>
 &nbsp;&nbsp; case READLOCK: <br>
 &nbsp;&nbsp; &nbsp; &nbsp; default:<br>
 &nbsp;&nbsp; &nbsp; pthread_rwlock_rdlock (&amp;mutex);<br>
 &nbsp;&nbsp; &nbsp; break;<br>
 &nbsp;&nbsp; &nbsp; &nbsp; case WRITELOCK:<br>
 &nbsp;&nbsp; &nbsp; pthread_rwlock_wrlock (&amp;mutex);<br>
 &nbsp;&nbsp; &nbsp; break;<br>
 &nbsp;&nbsp; &nbsp; }<br>
    <br>
 &nbsp; }<br>
    <br>
&nbsp; ~ReadWriteLock()<br>
 &nbsp; {<br>
 &nbsp; &nbsp; pthread_rwlock_unlock (&amp;mutex);<br>
 &nbsp; }<br>
};<br>
    <br>
Every servant has an own pthread_rwlock_t member, which is initialized in
its constructor, and before accessing the shared memory, there is a <br>
ReadWriteLock currentRead( servantRWMember, ReadWriteLock::READLOCK );<br>
    <br>
Maybe my terminology is not correct as this is a helper class.<br>
    <br>
Attila Pletyak<br>
    <blockquote type="cite" cite="mid:008301c0f33b$2e9bb3f0$0100000a@ddhome"><pre wrap=""><br>Dmitry<br><br><br><br></pre>
      </blockquote>
      <br>
</body></html>
--------------030307040507050500030009--