[Ace-users] [ace-users] ACE_RW_Process_Mutex
kul gupta
kulg123 at gmail.com
Tue Mar 4 00:06:26 CST 2008
Hello Doug,
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 Only change i did in the below code while using is - use of
ACE_Process_Mutex in place of ACE_RW_Process_Mutex in the higlighted area.
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
Thanks
Ruchita
On 3/3/08, Douglas C. Schmidt <schmidt at dre.vanderbilt.edu> wrote:
>
> Hi,
>
> Thanks for using the PRF.
>
> >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.
>
> Have you tried running this using ACE_Process_Mutex instead of
> ACE_RW_Process_Mutex to see what happens?
>
> Thanks,
>
> Doug
>
> >
> >
> >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 .
> >
> >
> >
> >The Code is written as below
> >
> >
> >
> >
> >
> >int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
> >
> >{
> >
> > ACE_RW_Process_Mutex m_RWMutex(ACE_TEXT("MyMutex"));
> >
> > if (agrc == 1)
> >
> > {
> >
> > while (1)
> >
> > {
> >
> > if (m_RWMutex.acquire_write() == 0)
> >
> > {
> >
> > ACE_OS::printf("Writer acquired...\n");
> >
> > ACE_OS::sleep(2);
> >
> > ACE_OS::printf("Writer releasing...\n");
> >
> > m_RWMutex.release();
> >
> > }
> >
> > }
> >
> > }
> >
> > else
> >
> > {
> >
> > while (1)
> >
> > {
> >
> > if (m_RWMutex.acquire_read() == 0)
> >
> > {
> >
> > ACE_OS::printf("Writer acquired...\n");
> >
> > ACE_OS::sleep(2);
> >
> > ACE_OS::printf("Writer releasing...\n");
> >
> > m_RWMutex.release();
> >
> > }
> >
> > }
> >
> > }
> >
> > return 0;
> >
> >}
> >
> >------=_Part_5765_23997741.1204541871901
> >Content-Type: text/html; charset=ISO-8859-1
> >Content-Transfer-Encoding: 7bit
> >Content-Disposition: inline
> >
> ><pre><font size="2">To: </font><a href="mailto:ace-bugs at cs.wustl.edu"
> target="_blank"><font size="2">ace-bugs at cs.wustl.edu</font></a></pre>
> ><div><font size="2">Please Ignore my previous mail ,the code was not
> complete.</font></div>
> ><div><font size="2">Subject: ACE_RW_Process_Mutex in single writer and
> multiple readers</font></div><pre><font size="2">ACE VERSION: 5.5.8</font></pre><pre><font
> size="2">HOST MACHINE and OPERATING SYSTEM:</font></pre><pre>
> ><font size="2"> </font></pre><pre><font size="2">Windows XP
> Professional and Enterprise Linux 5.0</font></pre><pre><font
> size="2">Version 2002</font></pre><pre><font size="2">TARGET MACHINE and
> OPERATING SYSTEM, if different from HOST:NO</font></pre>
> ><pre><font size="2">COMPILER NAME AND VERSION (AND
> PATCHLEVEL):</font></pre><pre><font size="2">Visual studio 2005</font></pre>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">THE $ACE_ROOT/ace/config.h FILE
> </span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">#include "ace/config-
> win32.h"<span style="mso-spacerun: yes"> </span>for
> windows</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">#include "ace/config-
> linux.h"<span style="mso-spacerun: yes"> </span>for
> linux</span></p><pre>
> ><font size="2">DOES THE PROBLEM AFFECT:</font></pre><pre><font
> size="2"> COMPILATION?
> NO</font></pre><pre><font
> size="2"> LINKING?
> NO</font></pre><pre><font
> size="2">
> EXECUTION? YES</font></pre>
> ><pre><font size="2"> OTHER
> </font></pre><pre><font size="2">
> SYNOPSIS:</font></pre>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">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)</span></p>
> >
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">Even a single Reader and single
> writer are not getting syncronized.Please provide with a sample program of
> ACE_RW_Process_Mutex.</span></p>
> >
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> </span></p><pre><font
> size="2">DESCRIPTION:</font></pre><pre><font size="2">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 .</font></pre>
> ><pre><font size="2"> </font></pre><pre><font size="2">The Code is
> written as below</font></pre><pre><span style="FONT-FAMILY: Arial"><font
> size="2"> </font></span></pre><pre><font size="2"> </font></pre>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">int ACE_TMAIN (int argc, ACE_TCHAR
> *argv[])</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">{</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">
> ACE_RW_Process_Mutex m_RWMutex(ACE_TEXT("MyMutex"));</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> if (agrc ==
> 1)</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> while (1)</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">
> if (m_RWMutex.acquire_write() ==
> 0)</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::printf("Writer acquired...\n");</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::sleep(2);</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::printf("Writer releasing...\n");</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> m_RWMutex.release();</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> else</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> while (1)</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">
> if (m_RWMutex.acquire_read() ==
> 0)</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> {</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::printf("Writer acquired...\n");</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::sleep(2);</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> ACE_OS::printf("Writer releasing...\n");</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> m_RWMutex.release();</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'">
> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier
> New'"> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> }</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'"> return
> 0;</span></p>
> ><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE:
> 10pt; FONT-FAMILY: 'Courier New'">}</span></p><pre><br
> style="mso-special-character: line-break"></pre>
> >
> >------=_Part_5765_23997741.1204541871901--
> >
>
>
> --
> Dr. Douglas C. Schmidt Professor and Associate Chair
> Electrical Engineering and Computer Science TEL: (615) 343-8197
> Vanderbilt University WEB:
> www.dre.vanderbilt.edu/~schmidt
> Nashville, TN 37203 NET: d.schmidt at vanderbilt.edu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.isis.vanderbilt.edu/pipermail/ace-users/attachments/20080304/fdd6f04a/attachment-0001.html
More information about the Ace-users
mailing list