Difference between revisions of "Coding Conventions"

From Agility
Jump to: navigation, search
(Multithreading)
(Critical sections should be small and predictable)
Line 13: Line 13:
 
lock(typeof(TranslateBO))
 
lock(typeof(TranslateBO))
 
{
 
{
 +
    //Anti-pattern do not put complicated business functions inside critical section
 
     transBO.getDataByKey(phraseKey);
 
     transBO.getDataByKey(phraseKey);
 
     result = transBO.detailData.syPhrase.Find(phraseKey);
 
     result = transBO.detailData.syPhrase.Find(phraseKey);

Revision as of 08:22, 24 January 2017


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 with access to database (for example business action).

Please AVOID below construction:

lock(typeof(TranslateBO))
{
    //Anti-pattern do not put complicated business functions inside critical section
    transBO.getDataByKey(phraseKey);
    result = 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))
{
    result = transBO.detailData.syPhrase.Find(phraseKey);
    [...]
}