Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Data with Mutex

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
I am using the following scheme to share data between multiple instances of the same application.

#pragma data_seg(".ID_DATA")

bool volatile gbID_1 = false; // In use flag for ID 1
bool volatile gbID_2 = false; // In use flag for ID 2
bool volatile gbID_3 = false; // In use flag for ID 3
bool volatile gbID_4 = false; // In use flag for ID 4
bool volatile gbKeyPressedID_1 = false; // Key pressed flag for ID 1
bool volatile gbKeyPressedID_2 = false; // Key pressed flag for ID 2
bool volatile gbKeyPressedID_3 = false; // Key pressed for ID 3 ID 1 handle
bool volatile gbKeyPressedID_4 = false; // Key pressed for ID 3 ID 1 handle
ANDLE volatile ghIDMutex = NULL; // Mutex for controlled access to this data area

#pragma data_seg()
#pragma comment(linker, "/SECTION:.ID_DATA,RWS")

I am using a Mutex (which is in this shared data - ghIDMutex )to protect this data, but could I have the main task that kicks off all these instances create the Mutex.

From what I have tried so far the Mutex is 0 in the other applications.

Any comments?

Sweep
 
Sweep,

You can NOT use the handle which was created by an instance in other instances of the program.
What you need to do is creating a named mutex. All instances must call CreateMutex, specifying the same name. That will redirect them to the same mutex.


Marcel
 
So if all instances use the same name i.e.
ghIDUMutex = CreateMutex(NULL, FALSE, "ID Mutex"); // Create Mutex for shared area

One other question can Task A which uses CreateProcess("Task B") to kick off several instances of Task B's all share this data
#pragma data_seg(".ID_DATA")
- and Mutex - if all use the same name.

Regards,

Sweep123



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top