Expand|Select|Wrap|Line Numbers
- int currentNumber = provider.GetCurrentNumber();
- if(provider.CanPassNumber(false, currentNumber))
- {
- currentNumber+=2;
- provider.SetNumber(currentNumber);
- }
Expand|Select|Wrap|Line Numbers
- if(condition)
- provider.SetNumber(numberToSet);
Is there anyway to lock provider.SetNumber until the first function finishes? The critical section is basically the currentNumber which can be changed by many places in the program.
I hope I made myself clear, if not let me know and I will try to explain myself better.
Also I made the functions really short for the example. In reality the function is much longer and makes changes to currentNumber many times so I don't really want to put a lock around the entire function. If I lock every call to provider.SetNumber and release it after I finish it can change during the time it is released before I lock it again to call provider.SetNumber. Honestly I'm also worried about locking the entire function because of performance and deadlock.