1 | #include <sys/wait.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <boost/interprocess/managed_shared_memory.hpp>
|
---|
4 |
|
---|
5 | int main( int argc, const char* argv[])
|
---|
6 | {
|
---|
7 | boost::interprocess::shared_memory_object::remove( "MySharedMemory");
|
---|
8 | boost::interprocess::managed_shared_memory segment(
|
---|
9 | boost::interprocess::create_only, "MySharedMemory", 4096);
|
---|
10 | pid_t child = fork();
|
---|
11 |
|
---|
12 | printf( "%s pthread_self %ld\n", child? "parent": "child", pthread_self());
|
---|
13 |
|
---|
14 | for( int i = 0; i < 1000000; ++i)
|
---|
15 | int *myclass = segment.find< int>( "aaa").first;
|
---|
16 |
|
---|
17 | printf( "Done %s\n", child? "parent": "child");
|
---|
18 |
|
---|
19 | if( 0 == child)
|
---|
20 | return 0;
|
---|
21 | wait( NULL);
|
---|
22 |
|
---|
23 | printf( "All Done\n");
|
---|
24 | }
|
---|
25 |
|
---|