Skip to main content
GameDev.net gamedev.net
🔒 Locked

Memory Manager/ thread synch - help!

Started by dxm Dec 11, 2002 at 6:51 AM 0 replies 350+ views
Original Post
dxm
dxm
hey everyone, i am building a gui in directx- and i wish an element of the system (e.g. a dialog box with buttons ok and cancel) to be able to free itself. I have written a MemManager class like so: class MemManager { int noElems; // no elems to be destroyed unsigned long elems[NO_ELEMS]; // array of pointers bool add(void *); // adds a pointer to the array bool destroy(); // free mem pointed to by elems array }; the dialog box has a pointer to a memManager object. My event handler for the gui uses the windows event thread and modifies the messages for my purposes. at the end of each game loop i call the memManagers destroy function. i want the dialog box to have an event handler method something like so: handleEvent(Message msg) { if (msg == "cancel") { // cancel is clicked m_parent->removeWindow(this); memManager->add(this); *** DODGY LINE!! ******* } } however, this does not work. I am almost certain it is because of thread synchronization between the event handler thread and the main thread. how could i fix this, or better yet, avoid it altogether?? thanks for reading this, hope i gave enough information, cheers
LordDeath
LordDeath
If you are using threads and there''s something that can be accessed in both threads, make sure its thread save (Use a semaphore or some other mechanism to make sure two things aren''t accessing it at the same time and botching things.)

Marc Hanson
Programmer on "Alter Echo"
Outrage Games - THQ

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.