Re: Shared memory delay
From: Carl Daniel [VC++ MVP] (cpdaniel_remove_this_and_nospam_at_mvps.org.nospam)
Date: 01/16/05
- Next message: William DePalo [MVP VC++]: "Re: Shared Memory in Terminal Services"
- Previous message: Carl-Fredrik Neikter: "RE: Shared Memory in Terminal Services"
- In reply to: Tim Haynes: "Shared memory delay"
- Next in thread: Tim Haynes: "Re: Shared memory delay"
- Reply: Tim Haynes: "Re: Shared memory delay"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 16 Jan 2005 10:02:28 -0800
Tim Haynes wrote:
> Hello,
>
> An odd problem...
>
> I have shared memory between two processes using CreateFileMapping
> (using the system pagefile) and MapViewOfFile, and this seems to work
> fine. Then I added some signalling between the processes using a
> semaphore, so that one process puts data in the shared memory and
> raises the semaphore (ReleaseSemaphore) - then the thread in the
> other process (waiting on the semaphore in WaitForSingleObject wakes
> up and reads the data from shared memory.
>
> Sounds great, except...there seems to be a bit of a delay for the
> updated memory to make its way from one process to the other. The
> semaphore wakes the second process up almost instantly, but when it
> reads the shared memory, the data isn't there. If I pause the second
> process after it wakes from the semaphore but before reading the
> value, then all is fine. Even a Sleep(0) seems to make it work, but
> I was wondering why the delay? Is Sleep(0) the right way to fix it?
>
> Note I tried SEC_NOCACHE in CreateFileMapping, but no difference.
As others have replied, there is NO shared memory delay - it simply can't
happen.
Your problem sounds to me like a synchronization problem. e.g. a
producer/consumer queue where the consumer is synchronized to the producer
but is lagging behind by one message.
Keep in mind that the shared memory is (most likely) at a different base
address in the two processes - make sure you're accounting for that
correctly everywhere you're computing addresses into the shared region.
-cd
- Next message: William DePalo [MVP VC++]: "Re: Shared Memory in Terminal Services"
- Previous message: Carl-Fredrik Neikter: "RE: Shared Memory in Terminal Services"
- In reply to: Tim Haynes: "Shared memory delay"
- Next in thread: Tim Haynes: "Re: Shared memory delay"
- Reply: Tim Haynes: "Re: Shared memory delay"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|