shared-memory

how do i change the shm_open path?

北城以北 提交于 2020-07-19 05:15:22
问题 i am currently developing an application on ubunto and calling shm_open, currently the default path is within /var/run/shm. however i need to change this to /tmp. simply trying the following does not work: fd = shm_open( "/tmp/test", O_RDWR | O_CREAT, 0777 ); can anyone please advise? 回答1: From the man page of shm_open(3) : name specifies the shared memory object to be created or opened. For portable use, a shared memory object should be identified by a name of the form /somename ; that is, a

Are writes on the PCIe bus atomic?

99封情书 提交于 2020-07-09 07:36:11
问题 I am a newbie to PCIe, so this might be a dumb question. This seems like fairly basic information to ask about PCIe interfaces, but I am having trouble finding the answer so I am guessing that I am missing some information which makes the answer obvious. I have a system in which I have an ARM processor (host) communicating to a Xilinx SoC via PCIe (device). The endpoint within the SoC is an ARM processor as well. The external ARM processor (host) is going to be writing to the register space

Python multiprocessing shared memory issues with C objects involved

拥有回忆 提交于 2020-07-09 04:54:14
问题 I am working on a program that uses an external C library to parse data from external sources and a Python library to run some optimisation problem on it. The optimisation is very time consuming so using several CPU would be a significant plus. Basically, I wrapped the C(++) structures with Cython as follows: cdef class CObject(object): cdef long p_sthg cdef OBJECT* sthg def __cinit__(self, sthg): self.p_sthg = sthg self.sthg = <OBJECT*> self.p_sthg def __reduce__(self): return (rebuildObject

How can I obtain a global mutex?

戏子无情 提交于 2020-06-28 09:21:29
问题 I'm trying to generate shared memory in a distributed manner; I also need the solution to be cross-platform. In order to do so, I need to synchronise the initialisation of this shared memory - using a mutex. This mutex, thus, needs to be shared. I've taken a look at this question: Interprocess reader/writer lock with Boost However, it suggests placing the mutex in shared memory, generated by a central process. This is the exact opposite of what I'm wanting to do. If I had this central process

What happens when reading or writing concurrently without a mutex

倖福魔咒の 提交于 2020-06-11 15:56:11
问题 In Go, a sync.Mutex or chan is used to prevent concurrent access of shared objects. However, in some cases I am just interested in the latest value of a variable or field of an object. Or I like to write a value and do not care if another go-routine overwrites it later or has just overwritten it before. Update: TLDR; Just don't do this. It is not safe. Read the answers, comments, and linked documents! Here are two variants good and bad of an example program, where both seem to produce

How to send a cv::Mat to python over shared memory?

别等时光非礼了梦想. 提交于 2020-04-16 02:52:11
问题 I have a c++ application that sends data through to a python function over shared memory. This works great using ctypes in Python such as doubles and floats. Now, I need to add a cv::Mat to the function. My code currently is: //h #include <iostream> #include <opencv2\core.hpp> #include <opencv2\highgui.hpp> struct TransferData { double score; float other; int num; int w; int h; int channels; uchar* data; }; #define C_OFF 1000 void fill(TransferData* data, int run, uchar* frame, int w, int h,

Memory lock to ensure shared data can be read from by many threads, but only written to by one?

烂漫一生 提交于 2020-04-07 05:38:18
问题 I am trying to write a C# program where values in a list A are checked against a particular value x in a thread. I would like the threads to compare their x values to each of the ones in the list, and if it is not found, I would like them to add their value x to A . The thread will then get a new x from a list in it's private memory, and begin comparing it to the values in A again. The objective of this program is to make A a list of unique values, and contain all of the values of the lists

Passing multiprocessing.RawArray to a C++ function

旧巷老猫 提交于 2020-03-25 05:18:30
问题 My Python application creates an array shared between processes using multiprocessing.RawArray . Now to speed up computation I want to modify this array from within a C++ function. What is a safe way to pass a pointer to the underlying memory to a C++ function that accepts a void * argument? The function is defined in a pxd file as: cdef extern from 'lib/lib.hpp': void fun(void *buffer) My naive attempt so far: buffer = multiprocessing.RawArray(ctypes.c_ubyte, 10000) clib.fun(ctypes.cast(self

Shared memory between NDK and SDK below API Level 26

不打扰是莪最后的温柔 提交于 2020-03-04 05:07:29
问题 Library written in c++ produces continuous stream of data and same has to be ported on different platforms. Now integrating the lib to android application, I am trying to create shared memory between NDK and SDK. Below is working snippet, Native code: #include <jni.h> #include <fcntl.h> #include <sys/mman.h> #include <linux/ashmem.h> #include <android/log.h> #include <string> char *buffer; constexpr size_t BufferSize=100; extern "C" JNIEXPORT jobject JNICALL Java_test_com_myapplication

How to get memory address from memfd_create?

爷,独闯天下 提交于 2020-02-21 06:30:27
问题 In my application I need to share memory between parent and child (using fork + execl ). I use memfd_create to allocate memory, because it provides a file descriptor, which may be conveniently used in child process (the discriptor is tied to stdin via dup2 before execl ) to attach to the allocated memory. I do not use write and read - I use pointers to read and write memory directly. The only piece of the puzzle which is left to solve is how to get the address of memory, allocated via fd =