Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a Dll (C++) who contains a data_seg that is used to share variables among others programs. It works and many program is using it (30+). The problem is that I added this library into a new project, but the variable that I try to access, never change its value. I have to restart the program and now its synchronized with the rest of the other programs and I can see the last value of a variable. Any clue?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
248 views
Welcome To Ask or Share your Answers For Others

1 Answer

You dont provide much information - like how you declare your variables or how you modify them. I assume you have written it properly as in MSDN documentation:

https://msdn.microsoft.com/en-us/library/h90dkhs0%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396

From your description - that variables are synchronized only after application restart, I can only suspect you have some caching problems. I suggest you make your variables volatile and use atomics to modify/read them.

for example:

#pragma data_seg("Shared")
volatile LONG g_mydata = 0;
#pragma data_seg()

#pragma comment(linker, "/Section:Shared,RWS")

now to modify g_mydata (increment by 1):

InterlockedExchangeAdd((PLONG)&g_mydata, 1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...