問題タブ [syncroot]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
2 に答える
5317 参照

.net - コレクションをロックするだけでなく、Collection.SyncRoot をロックするのはなぜですか?

ICollection の syncroot のポイントを理解しようとしています。コレクションをロックしないのはなぜですか?

0 投票する
2 に答える
2165 参照

c# - SyncRoot オブジェクトは本当にスレッドセーフですか?

私は SyncRoot の概念が初めてです。私が知る限り、ロックに使用されるオブジェクトは非公開にする必要があります。

ただしHashTable、パブリック プロパティ がありSyncRootます。これは、プライベート SyncRoot オブジェクトの単なるラッパーです。コレクションを列挙するときはロックすることをお勧めしますHashTable.SyncRoot

プライベートではなくなったため、デッドロックで失敗する可能性があるようです。本当にスレッドセーフですか?

独自のプライベート ロック メカニズムを作成するとどうなりますか? private readonly object _syncObject;

どちらが優れているのか、その理由は?

0 投票する
1 に答える
3723 参照

powershell - Powershell の SyncRoot プロパティ

この質問は、次のブログの関数 forward_dns に関するものです: http://powershellmasters.blogspot.com/2009/04/nslookup-and-powershell.html

たとえば、powershell に次のようなコードがあるとします。

このスニペットは、nslookup DOS コマンドを使用して DNS ルックアップを行います。これは DOS コマンドであるため、Invoke-Expression によって返されるオブジェクトは基本的に、出力の各行に 1 つずつ、文字列の配列です。

関数の例では、出力の 4 行目を取得するために、元の作成者は次の構文を使用します。

これもうまく機能することがわかりました:

このコンテキストでの SyncRoot の目的は何ですか?

0 投票する
3 に答える
22885 参照

c# - Correct way to lock the dictionary object

In my code I have a static dictionary object

which is throwing this error

I searched and found that this occurs because multiple threads try to access dictionary, but I do have lock on dictionary

Then I searched more and found that lock on dictionary doesn't prevent all the operations on it so I should be using lock on SyncRoot object of it like this to achieve what I want

But then I searched that using SyncRoot is not a good practice

On further search I found there is a ConcurrentDictionary for this purpose

  1. So can anybody please suggest me which is the best way to lock the dictionary
  2. If I use ConcurrentDictionary do I still need to use lock on it or will it handle everything by itself.
  3. If I have to use lock on ConcurrentDictionary, I have to use lock on it directly or again I have to lock the SyncRoot object for it

Thanks in advance!