[omniORB] Should I use mutex lock when write data on server?

Attila.Pletyak@anemo.com Attila.Pletyak@anemo.com
Sat, 28 Apr 2001 09:30:19 +0200


You definitely should use some type of locking because you can get strange
situations if not. The mutex solution you presented should work, but
omniORB also provides a mutex, called omni_mutex, which can be found in the
omnithread part of it.

Mutex in the read function means that only one person can read the data at
a time, which is maybe something you do not want. There is a ReadWriteLock
amongst the pthread functions to overcome this, but I experienced a problem
with the writelock part of it: if 10 concurrent write access were in
progress, 5 could go through the write lock procedure which is not what it
is all about, I think.

Sincerely,

Attila Pletyak
Anemo Ltd.
Hungary
http://www.anemo.com/


                                                                                                                                           
                    Victor Chen                                                                                                            
                    <victorcd@163.net>                  To:     omniorb-list@uk.research.att.com                                           
                    Sent by:                            cc:                                                                                
                    owner-omniorb-list@uk.resear        Subject:     [omniORB] Should I use mutex lock when write data on server?          
                    ch.att.com                                                                                                             
                                                                                                                                           
                                                                                                                                           
                    04/28/01 09:07 AM                                                                                                      
                                                                                                                                           
                                                                                                                                           



Dear sir:
    I use some large struct array in my server application, more than 10
client may change/read data in array at same time. as the server are
multithread,should I use thread mutex lock in server application?

myidl.idl

struct mystruct{
    long data1;
    string data2;
    .....
}
interface MyAdmin
{
    long readdata();
    long writedata(in mystruct InData);
}

Should I write "writedata" like this?
...writedata(.....
{
    pthread_mutex_lock(&mutex);
    ..... // write data here.
    pthread_mutex_unlock(&mutex);
}

...readdata(.....
{
    pthread_mutex_lock(&mutex);
    ..... // read data here.
    pthread_mutex_unlock(&mutex);
}