|
-
June 21st, 2012, 03:31 AM
#13
Re: Multiple-readers, single-writer synchronization lock between processes
Thanks for sticking with it.
I actually did solve it by abandoning semaphores as counters. I really liked your idea and it worked really great as long as all readers didn't crash within that specific critical section.
What I went with is a shared memory array for the readers count accessible for all readers and a writer. Each consisting of the following elements:
Code:
struct PROC_INFO{
DWORD dwProcID; //Process ID of reader
DWORD dwThreadID; //Thread ID that entered the reader-reading critical section
FILETIME ftCreatedTime; //Time when the process was created to resolve process ID ambiguity in case of a crashed process
};
Then while entering the reader critical section I'd add the calling thread and proc ID into this array and remove it when leaving the critical section. I had to write my own waiting function for the writer though. It'd loop with the Sleep(1) interval and try to open each process by its process ID and if it fails it then removes that element from the shared array. If the count of readers reaches 0 then the writer could begin writing. (Obviously all of these functions with the shared mem must be enclosed it its own mutex controlled critical section.) This approach seems to have eliminated any possible crashes. (Although it requires some additional attention to abandoned mutexes.)
Last edited by ahmd; June 21st, 2012 at 03:35 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|