c# - Critical section with state variable using Interlocked.Exchange -


i have critical section i'm trying protect using interlocked.exchange on member variable (int _state). code:

if (interlocked.exchange(ref _state, 1) == 0) {     // *** danger zone ***     try     {          //     }         {          _state = 0;     } } 

_state read elsewhere determine state, required.

my concern should exception occur in "danger zone", _state never set 0 , critical section never able entered again.

is there better way of doing while still being able set state variable? should using double lock pattern?


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -