質問

ってゆっくりと見つめて特徴のF#の表に示す。というのは特に格好で私が、興味を持っていることは、 MailboxProcessor.

  1. 同等のクライアントまで、フルのC#と利用ロックを解除します。きを考える MailboxProcessor 代替として、ロック?
  2. 以下の例にしてるわけではありませんので 何でも特にナイーブです まったくなにも見えることが す。


module Tcp =
    open System
    open System.Collections.Generic
    open System.Net
    open System.Net.Sockets
    open System.Threading    

    type SocketAsyncMessage =
        | Get of AsyncReplyChannel<SocketAsyncEventArgs>
        | Put of SocketAsyncEventArgs
        | Dispose of AsyncReplyChannel<MailboxProcessor<SocketAsyncMessage>>

    type SocketAsyncEventArgsPool(size:int) =             
        let agent = 
            lazy(MailboxProcessor.Start(
                    (fun inbox ->
                        let references = lazy(new List<SocketAsyncEventArgs>(size))       
                        let idleReferences = lazy(new Queue<SocketAsyncEventArgs>(size))                    
                        let rec loop () = 
                            async {
                                let! message = inbox.Receive()
                                match message with
                                | Get channel -> 
                                    if idleReferences.Value.Count > 0 then
                                        channel.Reply(idleReferences.Value.Dequeue())
                                    else    
                                        let args = new SocketAsyncEventArgs()
                                        references.Value.Add args
                                        channel.Reply args  
                                    return! loop()
                                | Put args ->
                                    if args = null then
                                        nullArg "args" 
                                    elif references.Value.Count < size then
                                        idleReferences.Value.Enqueue args
                                    else                                       
                                        if not(references.Value.Remove args) then
                                            invalidOp "Reference not found."                                        
                                        args.Dispose() 
                                    return! loop()
                                | Dispose channel ->
                                    if references.IsValueCreated then
                                        references.Value 
                                        |> Seq.iter(fun args -> args.Dispose())
                                    channel.Reply inbox 
                            }
                        loop())))

        /// Returns a SocketAsyncEventArgs instance from the pool.         
        member this.Get () =
            agent.Value.PostAndReply(fun channel -> Get channel)            
        /// Returns the SocketAsyncEventArgs instance to the pool. 
        member this.Put args =
            agent.Value.Post(Put args)
        /// Releases all resources used by the SocketAsyncEventArgsPool.
        member this.Dispose () =
            (this:>IDisposable).Dispose()  

        interface IDisposable with
             member this.Dispose() =
                if agent.IsValueCreated then
                    (agent.Value.PostAndReply(fun channel -> Dispose channel):>IDisposable).Dispose()
役に立ちましたか?

解決

ボックス(および類似を構築します)を使用しプログラミングモデルなロックを使用したという本質的に構築に非同期処となります。(なで共有の変更可能な状態でもうひとつの条件のことでありたいと考えております

の俳優-モデルと考えることができ、シリーズのネジ付きのミニプコミュニケーションが送受信データからです。各ミニ申込みを行っている単一のスレッドです。この不足の状態、ロックを描画します。

手続きのモデルと一番○○コードは、心臓、手続きのご使用中のスレッドレベル並行処理、および同期との通話をすること。の俳優-モデルの切り替えるこの世話のメッセージと物は非同期であるが、それぞれのオブジェクトが完全に同期.

わからないほF#っ解析コードでは、遠慮なく申しあげます。でんきしようとしているこ貼同期ル-シェルの周辺のメールボックスは、かねばな最善の対比包含されるメールボックスモデルに完全に).に実装では表示されるまで置き換え用として、ロックが解除されます。

他のヒント

最初のご質問:

のMailboxProcessorクラスは、メッセージキューラ独自のねじになります。い送信メッセージ のMailboxProcessorから任意のスレッドとして非同期と同期して.

なモデルできるスレッド間の通信を通じてメッセージ通の代わりにロックス/ミューテックス/ipcいます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top