[Ace-users] [ace-users] ACE_RW_Process_Mutex
kul gupta
kulg123 at gmail.com
Tue Mar 4 00:01:51 CST 2008
Subject: ACE_RW_Process_Mutex in single writer and multiple readers
ACE VERSION: 5.5.8
HOST MACHINE and OPERATING SYSTEM:
Windows XP Professional and Enterprise Linux 5.0
Version 2002
TARGET MACHINE and OPERATING SYSTEM, if different from HOST:NO
COMPILER NAME AND VERSION (AND PATCHLEVEL):
Visual studio 2005
THE $ACE_ROOT/ace/config.h FILE
#include "ace/config-win32.h" for windows
#include "ace/config-linux.h" for linux
DOES THE PROBLEM AFFECT:
COMPILATION? NO
LINKING? NO
EXECUTION? YES
OTHER
SYNOPSIS:
Use of ACE_RW_Process_Mutex.I developed a very simple program which needs to
be extended for Multiple readers and single writer ( shared memory concept
using a Hash Map with allocator)
Even a single Reader and single writer are not getting
syncronized.Pleaseprovide with a sample program of
ACE_RW_Process_Mutex.
DESCRIPTION:
After having a look into ACE_ROOT/examples/Threads ,I implemented the
following code using ACE_RW_Process_Mutex. and run in both Windows and
linux5.0. But in both the cases the synchronization is not happening .
Yes I have tried with ACE_Process_Mutex.Its working Fine in Windows
and linux.I m attaching the code of ACE_Process_Mutex along with its
output and also of ACE_RW_Process_Mutex along with its output
The Code is written as below (WITH ACE_RW_Process_Mutex)
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
int count =0;
float ltime=0;
ACE_RW_Process_Mutex m_RWMutex(ACE_TEXT("MyMutex"));
if (agrc == 1) // For server which is writing
{
while (1)
{
if (m_RWMutex.acquire_write() == 0)
{
ltime = ::GetTickCount();
ACE_OS::printf("Writer acquired...%d at:
%f\n",count++,ltime);
ACE_OS::sleep(2);
ltime = ::GetTickCount();
ACE_OS::printf("Writer releasing... ...%d at:
%f\n",count++,ltime);
m_RWMutex.release();
}
}
}
else //For Client which is reading
{
while (1)
{
if (m_RWMutex.acquire_read() == 0)
{
ltime = ::GetTickCount();
ACE_OS::printf("Reader acquired... ...%d at:
%f\n",count++,ltime);
ACE_OS::sleep(2);
ltime = ::GetTickCount();
ACE_OS::printf("Reader releasing...%d at:
%f\n",count++,ltime);
m_RWMutex.release();
}
}
}
return 0;
}
output is like this(WITH ACE_RW_Process_Mutex):
Writer
writer acquired 0 at 88110592
writer released 0 at 88112592
writer acquired 1 at 88112592
writer released 1 at 88114592
writer acquired 2 at 88114592
writer released 2 at 88116592
writer acquired 3 at 88116592
writer released 3 at 88118592
Reader
Reader acquired 0 at 88112872
Reader released 0 at 88114872
Reader acquired 1 at 88114872
Reader released 1 at 88116872
Reader acquired 2 at 88116872
Reader released 2 at 88118872
Reader acquired 3 at 88118872
output is like this (WITH ACE_Process_Mutex):
Writer
writer acquired 0 at 88560984
writer released 0 at 88562984
writer acquired 1 at 88562984
writer released 1 at 88564984
writer acquired 2 at 88566984
writer released 2 at 88568984
writer acquired 3 at 88570984
writer released 3 at 88572984
Reader
Reader acquired 0 at 88564984
Reader released 0 at 88566984
Reader acquired 1 at 88568984
Reader released 1 at 88570984
Reader acquired 2 at 88572984
Reader released 2 at 88574984
Reader acquired 3 at 88576984
Reader released 3 at 88578984
On 3/3/08, Matthew Gillen <mgillen at bbn.com> wrote:
>
> kul gupta wrote:
> > After having a look into ACE_ROOT/examples/Threads ,I implemented the
> > following code using ACE_RW_Process_Mutex. and run in both Windows and
> > linux5.0. But in both the cases the synchronization is not happening .
>
> It would help if were more specific about what actually /is/
> happening. Do
> you see the output messages in the wrong order? Do you never see some
> output messages?
>
> Matt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.isis.vanderbilt.edu/pipermail/ace-users/attachments/20080304/f03c928d/attachment-0001.html
More information about the Ace-users
mailing list