|The class SharedLock(3bobcat) is a wrapper around a pthread_mutex. SharedLock has member functions lock and unlock, with lock throwing an exception when it fails to obtain the lock (i.e., calling pthread_mutexs lock member fails, otherwise it waits until pthread_mutexs lock succeeds).|
|SharedLock is a convenience class for other shared memory classes. By itself SharedLock is unrelated to shared memory.|
|The class SharedBlock(3bobcat) defines a small object consisting of a SharedMutex and a (shared segment) id. If offers functionality to set and retrieve the id, and to lock and unlock the SharedMutex. SharedBlock objects are used by SharedSegment(3bobcat) objects to keep track of which segments actually contain the shared memory data. Its a bookkeeping helper class.|
|The class SharedSegment (cf. figure images/sharedsegment1.jpg) interfaces to actual shared memory. Its main member function is the static member create, returning a pointer to a newly allocated SharedMemory object.|
|The member create receives as its input parameters the number of blocks, the size of the segments allocated by SharedSegment, and the segments access mode (as used by, e.g., chmod(1)). It returns a pointer to the allocated SharedSegment, and its ID (set using a pointer to an int, passed as its first parameter).|
|Although the SharedSegment class defines an array of a single SharedBlock(3bobcat) object, in fact it will contain d_nBlocks SharedBlock objects. The member create first allocates a block of raw memory of the required total size. Next it initializes the first part of this raw, shared memory, using the SharedSegment constructor and placement new. Next, the remaining amount of raw shared memory is initialized with d_nBlocks - 1 SharedBlock objects, again using placement new (cf. figure images/sharedsegment2.jpg).|
|The class SharedPos(3bobcat) monitors position information in the shared memory segments managed by SharedSegment objects. SharedPos only has a default constructor, but offers a reset member receiving at construction time a pointer to a SharedSegment object.|
|The class SharedMemory(3bobcat) offers the standard interface to shared memory, defining members like read, get, write and put. It interfaces to a SharedSegment object, and uses a SharedPos object to keep track of the SharedMemorys offsets.|
|A SharedMemory object itself resides in a programs working memory, and not in the computers shared memory area. At any time the SharedMemory object only loads at most one actual block of the shared memory block managed by SharedSegment. The current position in the shared memory managed by SharedSegment is monitored by the SharedMemorys SharedBlock d_pos member.|
|Following read/write operations the offset is updated accordingly. Theres only one offset, which is used by [IO]?SharedStream objects when requesting or updating offsets. a SharedMemory object offers safeguards against inappropriate use. E.g., if no memory has been allocated yet it may thow exceptions. Also, offsets can never exceed the SharedMemorys maximum possible offset.|
|The class SharedMutex implements a non-recursive mutex that can be stored in shared memory. It merely offers lock and unlock members. Within one thread lcok should never be called repeatedly unless unlock is called first. The unlock member may safely repeatedly be called; once the mutex has been unlocked, repeated requests to unlock the mutex are simply ignored. When a SharedMutex is destroyed it calls unlock. Use SharedMemorys install member to define a SharedMutex object in shared memory, and use ptr->~SharedMutex() (with SharedMutex *ptr pointing at the SharedMutex object) to destroy it again.|
|The class SharedCondition implements a condition variable and an associated mutex, both created in shared memory controlled by a SharedMemory object. It offers all the functionality of std::condition_variable. A SharedCondition object itself is defined in a threads working memory, but interfaces to a Condition object containing a condition variable and a mutex which are installed in shared memory. The size of this Condition object is returned by the static member SharedCondition::size. SharedCondition members ensure that the thread has access to the Condition object, and that the shared memorys offset has not changed when returning from the SharedConditions members.|
|The class SharedStreambuf implements a std::streambuf specialization interfacing to a SharedMemory object. In addition to a default constructor which is an empty stub the class offers constructors which immediately interface to a SharedMemory object, as well as a member to (re)associate a SharedStreambuf object with a SharedMemory object.|
|o||SharedStream, ISharedStream, OSharedStream(3bobcat)|
|These stream classes offer stream-facilities operating on shared memory maintained by a SharedMemory object. The SharedStream class uses the SharedMemorys seek member for both seekp and seekg, and uses SharedMemorys offset member for both tellp and tellg. All shared stream objects, including ISharedStream, offer a member to initialize a SharedCondition|
|An overview of currently defined shared memory segments is shown by the command ipcs -ma. To remove a defined shared memory segment the command ipcrm -m <id> can be used, where <id> is the shared memory segments ID.|
See the sharedstream(3bobcat) man page.
Images referred to in this man-page are located in the source distribution in bobcat/documents/images, or they can be found in the standard location of documentation files in your distribution (e.g., they are located in /usr/share/doc/libbobcat3/images).
bobcat(7), ipcs(1), ipcrm(1), isharedstream(3bobcat), osharedstream(3bobcat), sharedblock(3bobcat), sharedcondition(3bobcat), sharedmemory(3bobcat), sharedmutex(3bobcat), sharedpos(3bobcat), sharedsegment(3bobcat), sharedstream(3bobcat), sharedstreambuf(3bobcat)
o bobcat_3.25.01-x.dsc: detached signature; o bobcat_3.25.01-x.tar.gz: source archive; o bobcat_3.25.01-x_i386.changes: change log; o libbobcat1_3.25.01-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.25.01-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location;
Bobcat is an acronym of Brokkens Own Base Classes And Templates.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (email@example.com).