JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C#


CSHARP.CONCURRENCY.STARVE.BLOCKING : Blocking in Critical Section (C#)

要旨

A blocking call occurs inside a synchronization block, hence increasing monitor contention and reducing performance.

Concurrency is an important but complex aspect of modern software. As a consequence, it is often used in an incorrect way, also because the subtleties of the C# memory model are not always understood. This checker identifies a large class of common programming errors due to incorrect uses of concurrency primitives, such as incorrect implementations of the singleton pattern and incorrect uses of the volatile field modifier, whose goal is to publish a field update to all executing cores. The latter, however, has a cost in terms of execution time.

プロパティ

クラス名 Blocking in Critical Section (C#)
日本語クラス名 Blocking in Critical Section (C#)
クラス分類 信頼性 (reliability)
ニーモニック CSHARP.CONCURRENCY.STARVE.BLOCKING
カテゴリー
CWE CWE:833 Deadlock
対応言語 C# で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Blocking in Critical Section (C#)"

using System;
using System.Threading;

public class Sleepyhead  
{

  private static readonly object syncLock = new object();

  public Sleepyhead() { }


  public void ZzZ()
  {
  
    lock (syncLock) 
    {
      Thread.Sleep(500);                                    // "Blocking in Critical Section (C#)" warning issued here 
    }

  }
  
   public void PrintDream() 
   {
  
    lock (syncLock) 
    {
    
     for (int i = 0; i < 1000000; i++)
      Console.WriteLine("A Midsummer Night's Dream\n\\n"    // "Blocking in Critical Section (C#)" warning issued here 
            + "*Theseus*:\n"
            +"\t"+  "Now, fair Hippolyta, our nuptial hour\n"
            +"\t"+  "Draws on apace; four happy days bring in\n"
            +"\t"+  "Another moon: but, O, methinks, how slow\n"
            +"\t"+  "This old moon wanes! she lingers my desires,\n"
            +"\t"+  "Like to a step-dame or a dowager\n"
            +"\t"+  "Long withering out a young man revenue.\n"
            + "*Hippolyta*:\n"
                // ...
       );
    }

  }
  
  // ...

}

To solve this issues, the programmer should handle the heavy Thread.Sleep() and Console.WriteLine() methods asynchronously outside the synchronized body.

解決法

Check if the warnings correspond to actual possible errors for a concurrent execution of the program.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.