shared-memory

wait and notify in C/C++ shared memory

最后都变了- 提交于 2019-11-27 20:10:30
问题 How to wait and notify like in Java In C/C++ for shared memory between two or more thread?I use pthread library. 回答1: Instead of the Java object that you would use to wait/notify, you need two objects: a mutex and a condition variable. These are initialized with pthread_mutex_init and pthread_cond_init . Where you would have synchronized on the Java object, use pthread_mutex_lock and pthread_mutex_unlock (note that in C you have to pair these yourself manually). If you don't need to wait

Efficiency of Multithreaded Loops

柔情痞子 提交于 2019-11-27 18:19:58
问题 Greetings noble community, I want to have the following loop: for(i = 0; i < MAX; i++) A[i] = B[i] + C[i]; This will run in parallel on a shared-memory quad-core computer using threads. The two alternatives below are being considered for the code to be executed by these threads, where tid is the id of the thread: 0, 1, 2 or 3. (for simplicity, assume MAX is a multiple of 4) Option 1: for(i = tid; i < MAX; i += 4) A[i] = B[i] + C[i]; Option 2: for(i = tid*(MAX/4); i < (tid+1)*(MAX/4); i++) A[i

Create a shared-memory vector of strings

三世轮回 提交于 2019-11-27 18:19:49
问题 I am trying to create a class managing a shared-memory vector of (std)strings. typedef boost::interprocess::allocator<std::string, boost::interprocess::managed_shared_memory::segment_manager> shmem_allocator; typedef boost::interprocess::vector<std::string, shmem_allocator> shmem_vector; shmem_mgr::shmem_mgr() : shmem_(create_only, SHMEM_KEY, SHMEM_SIZE), allocator_(shmem_.get_segment_manager()) { mutex_ = shmem_.find_or_construct<interprocess_mutex>(SHMEM_MUTEX)(); condition_ = shmem_.find

Fully managed shared memory .NET implementations? [closed]

时光怂恿深爱的人放手 提交于 2019-11-27 16:30:29
问题 I'm looking for free, fully-managed implementations of shared memory for .NET (P/Invoke is acceptable, mixed C++/CLI is not). 回答1: Sounds like you are looking for Memory-Mapped Files, which are supported in the .NET 4.0 BCL. Starting with the .NET Framework version 4, you can use managed code to access memory-mapped files in the same way that native Windows functions access memory-mapped files, as described in Managing Memory-Mapped Files in Win32 in the MSDN Library 回答2: Well, the .NET

Does different process has seperate copy of Shared Static variable or common copy?

感情迁移 提交于 2019-11-27 15:11:40
问题 I am trying to understand the fundamental of shared memory concept. I trying to create a shared library having one function and one STATIC array variable. I want to access static array variable through the function of that shared library. Here is my shared library //foo.c #include <stdio.h> static int DATA[1024]={1 ,2 ,3 ,...., 1024}; inline void foo(void) { int j, k=0; for(j=0;j<1024;j++) { k=DATA[j]; } k+=0; } I have created shared library object (libfoo.so) by following instructions from

how to use shared memory to communicate between two processes

此生再无相见时 提交于 2019-11-27 13:07:28
问题 I am trying to communicate between two processes. I am trying to save data(like name, phone number, address) to shared memory in one process and trying to print that data through other process. process1.c #include <stdio.h> #include <sys/shm.h> #include <sys/stat.h> int main () { int segment_id; char* shared_memory[3]; int segment_size; key_t shm_key; int i=0; const int shared_segment_size = 0x6400; /* Allocate a shared memory segment. */ segment_id = shmget (shm_key, shared_segment_size, IPC

Performance difference between IPC shared memory and threads memory

旧街凉风 提交于 2019-11-27 11:16:20
问题 I hear frequently that accessing a shared memory segment between processes has no performance penalty compared to accessing process memory between threads. In other words, a multi-threaded application will not be faster than a set of processes using shared memory (excluding locking or other synchronization issues). But I have my doubts: 1) shmat() maps the local process virtual memory to the shared segment. This translation has to be performed for each shared memory address and can represent

Do pthread mutexes work across threads if in shared memory?

拟墨画扇 提交于 2019-11-27 07:17:29
I found this: Fast interprocess synchronization method I used to believe that a pthread mutex can only be shared between two threads in the same address space . The question / answers there seems to imply: If I have two separate proceses A & B. They have a shared memory region M. I can put a pThread mutex in M, lock in A, lock in B, unlock in A; and B will no longer block on the mutex. Is this correct? Can pThread mutexes be shared in two separate processes? Edit: I'm using C++, on MacOSX. You need to tell the mutex to be process-shared when it's inited: http://www.opengroup.org/onlinepubs

making non-shared copies of boost::interprocess shared memory objects

女生的网名这么多〃 提交于 2019-11-27 06:32:00
问题 I have implemented various classes that are designed to be used in boost::interprocess shared memory segments. All their constructors employ allocator<void,segment_manager> references—some explicitly in the definitions I have written (like the Foo constructor below) and some simply because that's what the boost container definition requires, in boost library code that I should not be changing (like the IndexVector below). #include <boost/interprocess/managed_shared_memory.hpp> #include <boost

Writing to ashmem / why does android free ashmem?

柔情痞子 提交于 2019-11-27 06:16:13
问题 I want to share data between two (ndk-)processes. For this I use ashmem using this source. One process is continuously reading ( read_mem ) and one process is writing one time ( write_mem ). The problem is that the read process is not getting the values of the writer. AND By watching the maps of the reader I found that android deletes the shared memory file right after ashmem_create_region . read_mem.c // read_mem.c #include <stdio.h> #include <errno.h> #include <sys/mman.h> #include "ashmem