問題タブ [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.
.net - コレクションをロックするだけでなく、Collection.SyncRoot をロックするのはなぜですか?
ICollection の syncroot のポイントを理解しようとしています。コレクションをロックしないのはなぜですか?
対
c# - SyncRoot オブジェクトは本当にスレッドセーフですか?
私は SyncRoot の概念が初めてです。私が知る限り、ロックに使用されるオブジェクトは非公開にする必要があります。
ただしHashTable
、パブリック プロパティ がありSyncRoot
ます。これは、プライベート SyncRoot オブジェクトの単なるラッパーです。コレクションを列挙するときはロックすることをお勧めします。HashTable.SyncRoot
プライベートではなくなったため、デッドロックで失敗する可能性があるようです。本当にスレッドセーフですか?
独自のプライベート ロック メカニズムを作成するとどうなりますか?
private readonly object _syncObject;
どちらが優れているのか、その理由は?
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 の目的は何ですか?
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
- So can anybody please suggest me which is the best way to lock the dictionary
- If I use
ConcurrentDictionary
do I still need to uselock
on it or will it handle everything by itself. - If I have to use lock on
ConcurrentDictionary
, I have to uselock
on it directly or again I have to lock theSyncRoot
object for it
Thanks in advance!