Re: #pragma data_seg
<sabarad_arun@hotmail.com> wrote in message
news:1152696462.182217.326240@s13g2000cwa.googlegroups.com...
I am using a #pragma data_seg(".shared") in my application which is a
.exe.I am having a shared variable of type bool in the shared memory.I
have set it to FALSE initially.I am launching a second exe from this
application.I want to set it to TRUE in the InitInstance of my second
application.Can i do this?If yes then how?
Yes, I use this type of shared memory for things like this, and it works
very well. Keep in mind that as with all things shared between processes
(and threads), you need to avoid race conditions by using mutex or critical
section. I manage to avoid these since only one thread/process writes the
variables, and the other threads/processes, just compare the variables to
empty or FALSE. I also use things like the InterlockedExchange() functions
when setting these variables, to ensure that any reader process will read
the variables intact.
When using #pragma data_seg, you need to make sure to mark the data segment
as "shared" or else your variables won't really be shared. Here's how:
#pragma data_seg(".sdata")
BOOL sh_bIsRunning = FALSE; // NOTE: all variables must be initialized
in the declaration, or else they won't be shared
#pragma data_seg()
// This comment makes the above data segment shareable
// It replaces having to add a linker option to the project
#pragma comment(linker, "/SECTION:.sdata,rws")
-- David