Coding Conventions

From Agility
Revision as of 14:46, 23 January 2017 by Sychu (Talk | contribs) (Critical sections should be small)

Jump to: navigation, search


Multithreading

Critical sections should be small and predictable

To avoid dead-locks critical sections should be small enough to prove that dead lock is not possible. Critical section should not cover any complicated business task which access database (for example business action).

Please AVOID below construction:

lock(typeof(TranslateBO))
{

    transBO.getDataByKey(phraseKey);
    return transBO.detailData.syPhrase.Find(phraseKey);
}

In above example getDataByKey function is used inside critical section. It is NOT possible to prove that this function placed in critical section will never fall into dead-lock. Above example should be fixed with:

transBO.getDataByKey(phraseKey);
lock(typeof(TranslateBO))
{
    return transBO.detailData.syPhrase.Find(phraseKey);
}