
Hi. I'm trying to expose a "framebuffer API" via a C interface in a shared library. The idea is to have something like the following scenario: 1. Call "init" to initialize a sharable mutex and a shared memory segment for the framebuffer. 2. A process that wants to read the framebuffer would obtain a shared lock by calling ruauv_camReadLock() and get a handle on the mutex back (as a void*). 3. After doing what it needs to the framebuffer (which usually means copying it) it would call ruauv_camReadUnlock(void*) and send in the handle it got from step 2. I've implemented this and a test application that simply loops and does this repeatedly but the problem I have is that after exactly 65501 iterations I get an error stating: terminate called after throwing an instance of 'boost::interprocess::interprocess_exception' what(): Cannot allocate memory Here is a link to the relevant code that I'm using: http://pastebin.com/4ERTWEzj If it's of any relevance, I'm creating a shared library from the code above the main() in this snippet and then I'm compiling the main() into an executable and linking with the library. As I say, the for loop is able to iterate 65501 times and then fails the next time (the failure occurs at line 33 in the snippet above). I would really appreciate any help. -- Kær kveðja | With best regards Stefán Freyr Stefánsson Tölvunarfræðideild | School of Computer Science Sérfræðingur | Specialist Beint/Direct +354 599 6534 | GSM/Mobile +354 822 1667 Háskólinn í Reykjavík | Reykjavik University stefan@ru.is Menntavegur 1, Nauthólsvík | 101 Reykjavík | Iceland Sími/Tel +354 599 6200 | Fax + 354 599 6201 www.ru.is

Hello again.
Since I haven't gotten any replies to my question I went ahead and
created a working example in the hope that someone can take it and try
it out.
I've verified that this problem persists on at least one other system
(mine is 32 bit and the other one is 64 bit, both linux).
Here is the code:
http://pastebin.com/wpqk9x0N
Any ideas are appreciated, also any comments on whether I should be
using some other synchronization mechanism rather than
named_upgradable_mutex (since I don't need the upgradable part... just
need shared and exclusive locking).
Kind regards, Stefan Freyr.
On Tue, Apr 6, 2010 at 5:30 PM, Stefan Stefansson
Hi.
I'm trying to expose a "framebuffer API" via a C interface in a shared library.
The idea is to have something like the following scenario:
1. Call "init" to initialize a sharable mutex and a shared memory segment for the framebuffer. 2. A process that wants to read the framebuffer would obtain a shared lock by calling ruauv_camReadLock() and get a handle on the mutex back (as a void*). 3. After doing what it needs to the framebuffer (which usually means copying it) it would call ruauv_camReadUnlock(void*) and send in the handle it got from step 2.
I've implemented this and a test application that simply loops and does this repeatedly but the problem I have is that after exactly 65501 iterations I get an error stating:
terminate called after throwing an instance of 'boost::interprocess::interprocess_exception' what(): Cannot allocate memory
Here is a link to the relevant code that I'm using: http://pastebin.com/4ERTWEzj
If it's of any relevance, I'm creating a shared library from the code above the main() in this snippet and then I'm compiling the main() into an executable and linking with the library.
As I say, the for loop is able to iterate 65501 times and then fails the next time (the failure occurs at line 33 in the snippet above).
I would really appreciate any help.
-- Kær kveðja | With best regards Stefán Freyr Stefánsson
Tölvunarfræðideild | School of Computer Science Sérfræðingur | Specialist Beint/Direct +354 599 6534 | GSM/Mobile +354 822 1667 Háskólinn í Reykjavík | Reykjavik University stefan@ru.is Menntavegur 1, Nauthólsvík | 101 Reykjavík | Iceland Sími/Tel +354 599 6200 | Fax + 354 599 6201 www.ru.is
-- Kær kveðja | With best regards Stefán Freyr Stefánsson Tölvunarfræðideild | School of Computer Science Sérfræðingur | Specialist Beint/Direct +354 599 6534 | GSM/Mobile +354 822 1667 Háskólinn í Reykjavík | Reykjavik University stefan@ru.is Menntavegur 1, Nauthólsvík | 101 Reykjavík | Iceland Sími/Tel +354 599 6200 | Fax + 354 599 6201 www.ru.is

El 07/04/2010 08:30 a.m., Stefan Stefansson escribió:
Since I haven't gotten any replies to my question I went ahead and created a working example in the hope that someone can take it and try it out.
I am not sure if its related to your problem, but from your code it seems you are calling free() on a mutex allocated by new named_upgradable_mutex(). That has to be wrong (different memory allocation techniques, destructor not called, etc). You should call delete on your mutex, rather than free, and in a context where named_upgradable_mutex is complete (at ruauv_camReadUnlock I guess). Agustín K-ballo Bergé.- http://talesofcpp.blogspot.com
participants (2)
-
Agustín K-ballo Bergé
-
Stefan Stefansson