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

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -