[Ace-users] [ace-users] ACE_RW_Process_Mutex
kul gupta
kulg123 at gmail.com
Wed Mar 5 00:22:28 CST 2008
Hello Mathew
Below I m attaching my simple code using ACE_RW_Process_Mutex and its
output.
Description of the problem--
I also tried it using ACE_Process_Mutex by just replacing the
ACE_RW_Process_Mutex in code by ACE_Process_Mutex .With ACE_Process_Mutex
,synchronization is proper and writer and reader are acquiring and releasing
in correct order .(when writer is releasing, then only reader is acquiring
and vice versa. The output for the same is in last of the mail).
BUT when using ACE_RW_Process_Mutex ,the writer and reader are not in sync.
If we see the output for this as mentioned below, writer has acquired the
mutex at
88112592 millisec and released at 88114592 millisec i..e writer is working
for 2 sec and has acquired mutex for 2 sec.
(writer acquired 1 at 88112592
writer released 1 at 88114592)
Now when we see the Reader, it has acquired the mutex at 88112872 millisec.
(Reader acquired 0 at 88112872
Reader released 0 at 88114872)
This should ideally not happen as mutex is still with the writer and it is
relasing at 88114592 millisec.
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(); //number of millisec since the
system has started
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 count TimeStamp(in millisec)
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 count TimeStamp(in millisec)
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
Kul
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/20080305/389e7776/attachment.html
More information about the Ace-users
mailing list