C :: How To Apply Mutex Lock On Shared Memory
Jul 11, 2014
I was trying to put mutex lock on shared memory but my code is not working. What I want is that if some process is putting something on shared memory segment, other process should not be able to access that segment. For testing , I create a server program which put data in shared memory and client program which access the data.
To test it, I put break point after:
pthread_mutex_lock(&(init_lock));
But I see that client program was able to access shared memory.
Below is code:
Server: Code: pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
main()
{
char c;
[Code].....
View 1 Replies
Mar 25, 2014
Consider how to implement a mutex lock using an atomic hardware instruction. Assume that the following structure defining the mutex lock is available:
Code:
typedef struct {
int available;
}
lock; (available == 0)
indicates that the lock is available, and a value of 1 indicates that the lock is unavailable. Using this struct, illustrate how the following functions can be implemented using the test and set() and compare and swap() instructions:
void acquire(lock *mutex)
void release(lock *mutex)
Be sure to include any initialization that may be necessary.
View 2 Replies
View Related
Apr 13, 2014
Say now I have a dll, loaded and run by a 32bit program. One of the things that I access from the program in the dll are several 1024x1024 int buffers. However I would like to put some data into those buffers from a external process. And I would like a separate thread in that external process for each buffer. Is there any way I can make that memory space accessible to the external process so I can use my own multi threaded memory transfers to pass that data over provided I ensure that the original process doesn't try to do anything with that data? And I would like to do this without resorting to the Read/WriteProcessMemory functions which are not threadsafe. In short, I want to set up direct memory access between the 2 programs without creating any intermediate shared memory buffers ie I want to set permissions for an existing memory space. Is this possible?
View 1 Replies
View Related
Feb 9, 2013
I am not so experianced with c++ myself, but I need to evaluate if a certain idea might work.
I am working with a system for automation purposes that is running on a realtime OS in parallel to windows. Windows and the RTOS exchange data via shared memory. The application in the RTOS is compiled in C++. Now I would like to be able to influence the some data manipulation tasks in the RTOS application without changing the code of the RTOS application. So a concept like calling a dll.
My idea was to create a class with virtual methods in the RTOS application. The objects that are used should then be created on the Windows side with the same class prototype, but specific implementation of the virtual methods. The objects should then be moved to the shared memory, where they are used by the RTOS application.
Is something like this possible or am I completly on the wrong path?
View 4 Replies
View Related
May 27, 2014
In interprocess communication(IPC) when processe have to share data among each other,why cant they all connect to one single file and share data with basic file handling functions such as read and write?
Why do we need
shared memory(shmget shmat(),shmdt()..etc)
and
mapped memory(mmap(),munmap()..etc)
concepts?
View 3 Replies
View Related
Jan 16, 2014
I have one requirement to store an array of structure at shared memory. Also the shared memory should have one counter to store number of elements in the array.
I tried to look at some placed but didn't find anything relevant.
So my first question, is it possible that we can store two things on same shared memory. And second if not then how to achieve the same?
View 5 Replies
View Related
Dec 8, 2014
I am trying to initialize a 2D char array of strings into POSIX shared memory to be shared between 3 other processes. There are plenty of tutorials on how to use a pointer to share a single string or an integer between processes, but I could find no examples on how to initialize 1D or 2D arrays using mmap(). I have posted what I have so far below. It is the first program, which creates the shared memory object and initialize the array char files[20][2][100] with the value files[0][0][0] = '