Hi Berenguer,
Here are the exchanges myself and Ion have been having. Sorry this was not copied to the Boost list.
Steve.
==========================================================
Ion Gaztaņaga |
| More options | 26-Jul (6 days ago) |
Steven Wooding |
| More options | 14:31 (7 hours ago) |
===================================================================
RCS file: boost/shmem/shared_memory.hpp,v
retrieving revision 1.2
retrieving revision 1.4
diff -u -r1.2 -r1.4
--- shared_memory.hpp 2006/07/03 14:14:46 1.2
+++ shared_memory.hpp 2006/08/01 13:06:22 1.4
@@ -31,6 +31,7 @@
# include <semaphore.h> //sem_t* family, SEM_VALUE_MAX
# include <string> //std::string
# include <sys/stat.h> //mode_t, S_IRWXG, S_IRWXO, S_IRWXU,
+# include <sys/vfs.h> // fstatfs
# else
# error Unknown platform
# endif
@@ -534,8 +535,11 @@
inline bool shared_memory::GlobalNamedScopedMutex::acquire()
{
+ char globalMutexName[64];
+ strcpy(globalMutexName, "/boost_shmem_shm_global_mutex-");
+ strcat(globalMutexName, getenv("LOGNAME"));
mode_t mode = S_IRWXG | S_IRWXO | S_IRWXU;
- m_sem = sem_open("/boost_shmem_shm_global_mutex", O_CREAT, mode, 1);
+ m_sem = sem_open(globalMutexName, O_CREAT, mode, 1);
if(m_sem == ((sem_t*)-1))
return false;
m_acquired = sem_wait(m_sem) == 0;
@@ -616,6 +620,21 @@
}
else{
created = true;
+ // Check to see if there is enough space on the shared memory file system to create the
+ // new shared memory segment area
+ struct statfs statfsResult;
+ if ( fstatfs( m_shmHnd, &statfsResult) == -1)
+ {
+ this->priv_close_handles();
+ shm_unlink(name);
+ return false;
+ }
+ if ( size > ( statfsResult.f_bavail * statfsResult.f_bsize))
+ {
+ this->priv_close_handles();
+ shm_unlink(name);
+ return false;
+ }
// Set the memory object's size
if( ftruncate( m_shmHnd, size ) == -1 ) {
this->priv_close_handles();
========================================================
Ion Gaztaņaga |
| More options | 19:49 (2 hours ago) |
Steven Wooding |
| More options | 19:54 (2 hours ago) |
This does not solve the problem where two different users can share the
same segment, but at least, does not block new users.
I didn't know it was possible to create a shared memory region bigger
than the available. Shouldn't ftruncate fail if we try to do this?
Ion Gaztaņaga |
| More options | 20:10(1 hour ago) |
Steven Wooding |
| More options | 21:59 (0 minutes ago) |
Umm. That sounds really bad. However, this seems too linux specific,
since posix shared memory mounting point can be anywhere. I would need
to investigate this issue further to know if mmap can be told to reserve
all the memory, instead of waiting bus errors.