shared-memory

Looking for good analogy/examples for monitor verses semaphore

北城以北 提交于 2019-12-12 16:25:38
问题 A monitor is supposed to solve problems with semaphores in concurrent environments. I'm looking for a good analogy using a monitor verses semaphore. Please use information for the analogy: 4 tasks (TaskA, TaskB, TaskC, TaskD) 1 variable varX Each Task wants to manipulate varX based on some event. 回答1: Lets say a bunch of patients wants to go see a doctor. A semaphore implementation would be they all stand outside the door to the office, as soon as one patient comes out, they all try to

android mmap failed: invalid argument (errno 22)

无人久伴 提交于 2019-12-12 12:41:00
问题 I was porting/compiling androidvncserver for my android device, but when I run it (as root) I keep getting mmap errors. The offending code looks like this: /* Android does not use /dev/fb0. */ #define FB_DEVICE "/dev/graphics/fb0" if ((fbfd = open(FB_DEVICE, O_RDONLY)) == -1) { printf("cannot open fb device %s\n", FB_DEVICE); exit(EXIT_FAILURE); } <SNIP> fbmmap = mmap(NULL, pixels * bytespp, PROT_READ, MAP_SHARED, fbfd, 0); if (fbmmap == MAP_FAILED) { printf("mmap failed errno = %d\n", errno)

Does mmap share memory with all processes?

≯℡__Kan透↙ 提交于 2019-12-12 09:50:55
问题 When I do this : myProgram.h myProgram.c struct PipeShm { // all my fields // more // ... }; struct PipeShm myPipe = { /* initialization for all fields */ }; struct PipeShm * sharedPipe = &myPipe; void func() { sharedPipe = mmap (NULL, sizeof * sharedPipe, PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, -1, 0); } When I mmap the pointer sharedPipe , if I invoke from main() any methods from myProgram code, would all processes share the exact shared memory that I shared with myPipe struct?

Why are these two addresses not the same?

戏子无情 提交于 2019-12-12 06:49:31
问题 shmget.c: #include<sys/types.h> #include<string.h> #include<sys/ipc.h> #include<sys/shm.h> #include<stdio.h> main() { key_t key; int shmid; char* addr1; key = ftok("/home/tamil/myc/pws.c",'T'); shmid = shmget(key,128*1024,IPC_CREAT|SHM_R|SHM_W); addr1 = shmat(shmid,0,0); printf("\nIPC SHARED MEMORY"); printf("\n SENDER ADDRESS"); printf("\nTHE ADDRESS IS %p",addr1); printf("\nENTER THE MESSAGE:"); scanf("%s",addr1); printf("\nMESSAGE STORED IN %p IS %s",addr1,addr1); } shmget2.c: #include<sys

An example of pushing and retrieving of an NSObject's pointer in ObjC from Shared Memory?

怎甘沉沦 提交于 2019-12-12 05:23:33
问题 I know that there are better ways of sharing objects such as distributed objects but my situation is quite difficult. I'm working on two iPhone apps which are running parallely and need to share an object. That object happens to be a CALayer and it needs to be accessible by both applications. Second application adds its own CALayer to the first app's CALayer and does its work there. The only way I see is using Shared Memory, but I couldn't find any useful examples of doing exactly what I need

Eigen fixed-size matrices in shared memory using boost interprocess

喜欢而已 提交于 2019-12-12 04:55:55
问题 I like to place Eigen fixed-size matrices into the shared memory. But on execution I am getting the following error: /usr/include/eigen3/Eigen/src/Core/DenseStorage.h:78: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 16>::plain_array() [with T = double; int Size = 2; int MatrixOrArrayOptions = 0]: Assertion `(reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel

Creating a 2D array in the shared memory

倖福魔咒の 提交于 2019-12-12 04:38:26
问题 I want to create a program to store data in a 2D array. This 2D array should be created in the shared memory. #include <stdio.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> key_t key; int shmBuf1id; int *buf1Ptr; main(int argc, int *argv[]) { createBuf1(); } createBuf1() { key = ftok(".",'b'); shmBuf1id = shmget(key,sizeof(int[9][9]),IPC_CREAT|0666); if(shmBuf1id == -1 ) { perror("shmget"); exit(1); } else { printf("Creating new Sahred memory sement\n"); buf1Ptr[3] =

protect a shared memory segment with semaphore does not work

我与影子孤独终老i 提交于 2019-12-12 04:37:25
问题 I have a programm which creates 1000 child processes. Each process should access to a int variable, which is stored in a shared memory segment. To protect the int variable I have created a semaphore: #define _XOPEN_SOURCE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/sem.h> #include <sys/ipc.h> #include <sys/shm.h> #define KEY 1000 #define LOCK -1 #define UNLOCK 1 int *ptr; int pid; int shm_id; int sem

Share DLL between 2 process in .net

自古美人都是妖i 提交于 2019-12-12 04:36:06
问题 I have 2 Winforms project and 1 Library project in my solution, this 2 winforms will be launched independently by the user. What happens right now is that the shared DLL is instantiated in memory per process, even if both exes are in the same folder or if the DLL is in the GAC. But I wish I could reuse the same DLL between those 2 process. I found a workaround, create a third project and instantiate the winforms project from there, in this case the DLL will be only instantiated once in memory

Interpreting Section object in kernel dump

試著忘記壹切 提交于 2019-12-12 04:35:26
问题 I'm trying to track down issues with a 3thParty application. The path currently being investigated is to look into a Section object that get's created in each process: rpsPdf10.mutex . If the name of the object is any indication for it's intended usage, I'm not sure why they choose a Section object and use it as a Mutex but that's likely largely irrelevant. Using LiveKd I've issued following command's trying to get detailed info of the Section object 0: kd>!process 0 0 3thParty.exe ...