【发布时间】:2019-11-04 23:35:10
【问题描述】:
我计划使用boost::interprocess 在 C++ 和 Python 进程之间共享内存。假设我需要 boost 提供的互斥锁以确保只有一个进程可以访问内存,我如何让 python 确认并解锁/锁定 boost 创建的互斥锁?
【问题讨论】:
标签: python c++ c++11 boost multiprocessing
我计划使用boost::interprocess 在 C++ 和 Python 进程之间共享内存。假设我需要 boost 提供的互斥锁以确保只有一个进程可以访问内存,我如何让 python 确认并解锁/锁定 boost 创建的互斥锁?
【问题讨论】:
标签: python c++ c++11 boost multiprocessing
似乎有两种明显的方法:
boost 查找现有的python 包装器
使用上面链接中的示例和一些猜测,你会得到这样的东西:
static PyObject *mySharedMutex_lock(PyObject *self, PyObject *args)
{
const char *objectName;
int sts;
if (!PyArg_ParseTuple(args, "s", &objectName))
{
return NULL;
}
boost::interprocess::named_mutex mutex(open_or_create, objectName);
mutex.lock();
return Py_None;
}
显然,您需要上面链接中的说明中的其他样板,并可能提供一种解锁互斥锁的方法。让这个工作看起来不是很繁重。
【讨论】: