Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


problem with threads accessing the same memory...

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Oct 23, 2010 5:23 pm    Post subject: problem with threads accessing the same memory... Reply with quote

I have 2 threads accessing the same memory, an array. My program crashes, and I think it is because of this array. The 2 threads use this array and can modify it at any moment. I think that when the first thread is using the array (eg. in a loop) ,the other one changes the values of the array and a mess follows and my program crashes. What I want to do it to make sure one thread has finished using the array and then releasing that array for the other thread. I know this can be done but haven't done anything like that before.

EDIT: I think I've got the idea, but I'm sure windows has already a built api function for this. I am thinking setting another global variable like a flag like this:

Code:

BYTE a;
a = 0; <-- no thread is currently using the array
a = 1; <-- array is being used by some thread,, no access


and setting a=1 in every thread and the thread that is faster will gain access, the other one will wait in a loop until a = 0 again...
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Oct 23, 2010 5:49 pm    Post subject: Reply with quote

I think C++0x has support for atomic datatypes?

I'm pretty clueless about threading, but you will probably have a much easier time if you just use a library that does the heavy lifting. I think Intel has one and there is also OpenMP
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sat Oct 23, 2010 6:14 pm    Post subject: Reply with quote

Look into critical sections:
http://msdn.microsoft.com/en-us/library/ms682530%28VS.85%29.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Oct 23, 2010 6:17 pm    Post subject: Reply with quote

Yes read up on critical sections, mutexs and semaphores.
Back to top
View user's profile Send private message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Sat Oct 23, 2010 6:28 pm    Post subject: Reply with quote

thank you for all answers, that was what I was looking for,, critical sections Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites