Boost如何在Windows上为interprocess_mutex生成唯一名称

// boost/interprocess/sync/windows/sync_utils.hpp
void* open_or_create_mutex(const sync_id &id)
{
    NameBuf name;
    fill_name(name,id);
    permissions unrestricted_security;
    unrestricted_security.set_unrestricted();
    winapi_mutex_wrapper mtx_wrapper;
    mtx_wrapper.open_or_create(name,unrestricted_security);
    throw_if_error(mtx_wrapper.handle());
    return mtx_wrapper.release();
}

sync_idQueryPerformanceCounter调用的结果初始化,例如:

LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
sync_id = counter.QuadPart;

namesync_id生成:

name = "Global\\boost.ipc" + hex_string(sync_id);

如何通过上述算法使Boost产生唯一的“名称”? sync_id是一个int64_t值,看来这可能不是唯一值。

iCMS 回答:Boost如何在Windows上为interprocess_mutex生成唯一名称

使用给定的名称。它不应该是唯一的。进程间同步原语的全部要点是它们没有唯一的名称,以便可以从不同的进程进行访问。

如果要使用专用互斥锁,请使用Boost Thread互斥锁或std :: mutex(有定时/共享版本)。

本文链接:https://www.f2er.com/1845193.html

大家都在问