mutual exclusions problem

im trying to figure this out and Im having problems getting it to not go into an infinite loop. The exchange function is actually implementing mutual exclusion for there different functions. This work when i use the "atomic" keyword on the Exchange function. I am not asking for the answer. Just a direction. thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

atomic bool TS(bool& lock)
{
    bool save;
    save = lock;
    lock = true;
    return save;
}




void Exchange(int& a, int& b)
{
    // 
	bool lock_TS = false;
	
	while(TS(lock_TS)){} //spin lock
			
		
	
	
	//critial section begin
		temp = a;		
		a = b;			
		b = temp;			
	//critial section end
	
		lock_TS = false;
		
	}
Are you using some kind of library/compiler extension?

'atomic' is not a C++ keyword. There's a C++11 atomic template class but it does not work how you are using it here.
Im actually doing this in a BACI environment using C--. Im still stuck. I cannot get mutual exclusion for Exchange(). Again, Exchange() is implementing mutex for three separate functions. However, it itself needs mutual exclusion. Im trying to get there using a testAndSet function that has interrupts disabled(ie atomic). But for some reason the lock never opens and all functions get stuck in a deadlock. Again, not asking for the answer, just some direction, conceptually for the mutex testAndSet construct.


Last edited on
closed account (N36fSL3A)
Sorry to say this, but I don't think you'll get much help with this. (Actually I might be wrong.)

I'm not saying you certainly wont get help, but these forums specialize in C/C++, sometimes Java, sometimes C# and scripting languages. I don't think C-- is a largely known to these forums. Is there some sort of C-- forum?
Does it say C-- on the forum? :D

You should look for one that is dedicated to C--.
Wow, hilarious! I've not seen reference to this in so long. The domain is no longer maintained. Had to go to wayback to get the most recent info. I doubt you can find support for it.

If I might ask, what are you using it for?
Topic archived. No new replies allowed.