Overview
Features
Download
Documentation
Community
Add-Ons & Services

Non-file-mapped shared memory problem

Please post support and help requests here.

Non-file-mapped shared memory problem

Postby setsu » 28 Jun 2010, 02:39

In the document below says "If server is set to false, the shared memory region will be unlinked by calling shm_unlink (on POSIX platforms) when the SharedMemory object is destroyed.".
http://pocoproject.org/docs/Poco.SharedMemory.html#9927
But source code is not coded like that.

Poco/SharedMemory_POSIX.cpp
Code: Select all
void SharedMemoryImpl::close()
{
   if (_fd != -1)
   {
      ::close(_fd);
      _fd = -1;
   }
//   if (!_fileMapped && _server)   // logic inverted!
   if (!_fileMapped && !_server)
   {
      ::shm_unlink(_name.c_str());
   }
}

Because of this problem, omry raised following topic:
viewtopic.php?f=12&t=425&p=1319&hilit=SharedMemory#p1319

# I hope this change will be merged into 1.3.7.
Last edited by setsu on 24 Dec 2010, 03:48, edited 1 time in total.
setsu
 
Posts: 11
Joined: 12 Jan 2008, 11:29
Location: Japan

Re: Non-file-mapped shared memory problem

Postby guenter » 02 Jul 2010, 08:37

fixed in 1.3.7, rev. 1375
guenter
 
Posts: 1107
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Non-file-mapped shared memory problem

Postby setsu » 24 Dec 2010, 03:40

I checked them with the Poco v1.4.0 codes, then I found still there's problem.
To fix them, we have to change these things:

[1 of 2] Document, i.e. comments in SharedMemory.h, has to be changed:
Code: Select all
85c85
<       /// If server is set to false, the shared memory region will be unlinked
---
>       /// If server is set to true, the shared memory region will be unlinked


[2 of 2] SharedMemory_POSIX.cpp has to be changed:
Code: Select all
65c65
<    int flags = O_CREAT;
---
>    int flags = (_server == true) ? O_CREAT:0;
77c77
<    if (-1 == ::ftruncate(_fd, size))
---
>    if (_server == true && -1 == ::ftruncate(_fd, size))
149c149
<    if (!_fileMapped && !_server)
---
>    if (!_fileMapped && _server)

With the code chages above, client for the shared memory works with no problem.

Test codes for this problem attached.
Attachments
SharedMemoryTestCode.zip
(16.74 KiB) Downloaded 124 times
setsu
 
Posts: 11
Joined: 12 Jan 2008, 11:29
Location: Japan

Re: Non-file-mapped shared memory problem

Postby guenter » 27 Dec 2010, 16:47

guenter
 
Posts: 1107
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests