Enumerable

Top / Coding / .NET / 標準ライブラリ / Enumerable
 

ページ構成
−Top
  • −Coding
    • −.NET
      • ・.NETStandard
      • +3rdPartyライブラリ
      • ・AOP
      • +ASP.NET
      • ・CD.DVDにデータを書き込む
      • ・DPAPI
      • ・DryadLINQ
      • ・EXEとDLLを1つにまとめる
      • ・GPGの使用
      • +IEの操作
      • ・IMEの日本語確定によるEnterの判定
      • ・MACアドレスの取得
      • ・MSTest
      • ・MeCabの利用
      • ・MetroStyleApps
      • ・Microsoft.VisualBasic
      • ・NuGetパッケージの作成
      • ・Tipsまとめサイト
      • ・UACへの対応
      • ・VS2012単体テスト
      • ・VS以外のIDE
      • +Verごとの違い
      • ・VisualStudioビルドイベント
      • ・VisualStudio拡張機能
      • +WPF
      • ・WebAutomation
      • ・WinFormsメモ
      • +WinRT
      • ・csc.exeの使い方
      • ・msbuild
      • ・yield_return
      • ・アセンブリの難読化
      • ・ウィンドウ位置の正しい復元
      • ・クリップボードの監視
      • ・グローバルフック
      • ・コマンドラインツールの作成
      • ・コンポーネントの作成
      • ・サービスの開発
      • ・デバッグに関するTips
      • ・フォント幅の取得
      • ・マルチスレッド処理の勘所
      • ・モックフレームワーク
      • ・モニタの電源制御
      • ・ユーザー独自の設定ファイル作成
      • +開発環境
      • ・技術資料
      • ・継承インターフェース抽象クラスの使い分け
      • ・重複起動の禁止
      • ・数値解析
      • ・多言語化
        • ・DataContractJsonSerializer
        • ・DataGridView
        • ・Enumerable
        • ・HttpClient
        • ・IEnumerable
        • ・IEnumerator
        • ・IEnumerator_yield
        • ・LINQ
        • ・Regex
        • ・SmtpClient
        • ・ハッシュ値の計算
        • ・圧縮
      • ・標準ライブラリに関して
      • ・勉強メモ
    • +CUDA
    • +JavaScript
    • +MSOffice
    • +PHP
    • +PowerShell
    • +Python
    • +Ruby
    • +VBA
    • +misc
    • +画像処理
  • +Server
  • +memo
  • +misc
  • +カメラ
  • +科学技術
  • +記事
  • +数値解析
最新の10件
2018-01-16 更新
  • misc/Hardware/各種プロセッサの倍精度演算性能
2017-11-27 更新
  • Coding/misc/raspberrypi
2017-11-02 更新
  • Coding/.NET/NuGetパッケージの作成
2017-10-19 更新
  • Coding/MSOffice/VSTO/ThisAddin_Startupに処理を書く問題が起きる
2017-06-16 更新
  • Coding/.NET/VisualStudioビルドイベント
2017-05-28 更新
  • misc/Hardware/タブレット向けCPU/複製
2017-05-25 更新
  • Coding/Python/CloudVision
2017-05-24 更新
  • misc/ロードバイク/サイクルロード/奈良
2017-05-11 更新
  • misc/ソフトウェア/文章/文章校正、作成支援ツール
2017-03-15 更新
  • misc/ソフトウェア/プロジェクト管理ツール

Powered By

b_pukiwiki.official.png

edit

このページの目次

  • 概要
  • 参考資料(未整理)
    • IEnumerrator/IEnumerableについて
      • 【MSDN 公式】
      • 【内部実装について MONOの場合】
      • 【参考記事】
      • 解決策(具体的なロックの実装)
      • 番外編
    • LINQ Enumerableについて

概要 †

「Enumeratorが、thread safeで、MoveNext()が、非thread safe」
であることについて理解を深めるための資料集め。

↑

参考資料(未整理) †

↑

IEnumerrator/IEnumerableについて †


↑

【MSDN 公式】 †

IEnumerator, IEnumerableについてMSDNの記載 http://msdn.microsoft.com/ja-jp/library/system.collections.ienumerator%28v=vs.110%29.aspx

The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

列挙子はコレクションへの排他アクセス権を持たないため、コレクションの列挙処理は、本質的にはスレッド セーフな処理ではありません。 コレクションが同期されている場合でも、他のスレッドがそのコレクションを変更する可能性はあり、そのような状況が発生すると列挙子は例外をスローします。 列挙処理を確実にスレッド セーフに行うには、列挙中にコレクションをロックするか、他のスレッドによって行われた変更によってスローされる例外をキャッチします。

↑

【内部実装について MONOの場合】 †

MonoでのIEnumerable.GetEnumeratorの実装(eg. ArrayList.cs)を読んでみても
特に排他処理をしていないので、thread safeには見えない。

https://github.com/mono/mono/tree/a31c107f59298053e4ff17fd09b2fa617b75c1ba/mcs/class/corlib/System.Collections

↑

【参考記事】 †

2012の記事:c# - Is this collection actually thread safe? Is concurrent Iterating, querying and modifying safe? - Code Review Stack Exchange
http://codereview.stackexchange.com/questions/7276/is-this-collection-actually-thread-safe-is-concurrent-iterating-querying-and-m

C#: How can I make an IEnumerable<T> thread safe? - Stack Overflow
http://stackoverflow.com/questions/1605745/c-how-can-i-make-an-ienumerablet-thread-safe

未読: c# - Is returning an IEnumerable<> thread-safe? - Stack Overflow
http://stackoverflow.com/questions/10232631/is-returning-an-ienumerable-thread-safe

未読:Iterating atomically - Jon Skeet: Coding Blog
http://msmvps.com/blogs/jon%5Fskeet/archive/2009/10/23/iterating-atomically.aspx


↑

解決策(具体的なロックの実装) †

(2010) Thread-safe enumeration in C#
http://www.codeproject.com/Articles/56575/Thread-safe-enumeration-in-C


↑

番外編 †

解決策だけどたぶんふつう使えない

Microsoft.TeamFoundation.Framework.Serverに、TryMoveNextっていうthread safeなメソッドがあるっぽい?

TeamFoundationDataReader.TryMoveNext Method (Microsoft.TeamFoundation.Framework.Server)
http://msdn.microsoft.com/ja-jp/library/microsoft.teamfoundation.framework.server.teamfoundationdatareader.trymovenext(v=vs.100).aspx

↑

LINQ Enumerableについて †

LINQ Enumerable
http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
この型のすべてのパブリック static (Visual Basic では Shared) メンバーは、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

拡張メソッドは、thread safe
instance members (?)は、not thread safe


トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索   ヘルプ   最終更新のRSS
Last-modified: 2013-12-16 (月) (2588d)
Site admin: D*isuke YAMAKAWA

PukiWiki 1.4.7 Copyright © 2001-2006 PukiWiki Developers Team. License is GPL.
Based on "PukiWiki" 1.3 by yu-ji. Powered by PHP 5.3.29. HTML convert time: 0.039 sec.