本文整理汇总了C++中SharedMemory::mark_for_release方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::mark_for_release方法的具体用法?C++ SharedMemory::mark_for_release怎么用?C++ SharedMemory::mark_for_release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedMemory
的用法示例。
在下文中一共展示了SharedMemory::mark_for_release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
TEST(SharedMemoryTest, ShareFork) {
bool was_child = false;
{
SharedMemory memory;
EXPECT_TRUE(memory.get_block() == nullptr);
EXPECT_TRUE(memory.is_null());
std::string meta_path = base_path() + std::string("_share_fork");
COERCE_ERROR(memory.alloc(meta_path, 1ULL << 21, 0));
memory.get_block()[3] = 42;
pid_t pid = ::fork();
if (pid == -1) {
memory.mark_for_release();
ASSERT_ND(false);
EXPECT_TRUE(false);
} else if (pid == 0) {
// child
SharedMemory memory_child;
memory_child.attach(meta_path);
EXPECT_FALSE(memory_child.is_null());
EXPECT_EQ(1ULL << 21, memory_child.get_size());
EXPECT_EQ(meta_path, memory_child.get_meta_path());
EXPECT_NE(0, memory_child.get_shmid());
EXPECT_NE(0, memory_child.get_shmkey());
EXPECT_EQ(0, memory_child.get_numa_node());
EXPECT_EQ(42, memory_child.get_block()[3]);
EXPECT_FALSE(memory.is_owned());
was_child = true;
} else {
// parent
int status;
pid_t result = ::waitpid(pid, &status, 0);
EXPECT_EQ(pid, result);
EXPECT_EQ(0, status);
}
memory.release_block();
}
if (was_child) {
::_exit(0); // otherwise, it goes on to execute the following tests again.
}
}