﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on A minimal actor framework</title><description>Johannes,
Yes, we didn't have guids for posts, so it did that. Fixed now</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment24</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment24</guid><pubDate>Fri, 13 May 2011 07:54:43 GMT</pubDate></item><item><title>Johannes Hansen commented on A minimal actor framework</title><description>Hi Ayende, everytime you've posted a message lately my google reader has marked ALL your previous posts as new posts as well. There might be something wrong with your blog engine. Just letting you know. :)</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment23</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment23</guid><pubDate>Fri, 13 May 2011 07:52:18 GMT</pubDate></item><item><title>Ayende Rahien commented on A minimal actor framework</title><description>Michael,
  
Take a look at the next post
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment22</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment22</guid><pubDate>Thu, 05 May 2011 14:12:00 GMT</pubDate></item><item><title>Michael Reichenauer commented on A minimal actor framework</title><description>Skip/delete my previous comment, I failed to notice that this was already covered in your next post
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment21</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment21</guid><pubDate>Thu, 05 May 2011 11:07:21 GMT</pubDate></item><item><title>Michael Reichenauer commented on A minimal actor framework</title><description>A problem with using Task.Factory.StartNew(action) is that a pool thread is blocked while an action running. For a single Actor in a program, this is not a big problem (only one thread from the pool), but if there would be multiple Actors running concurrently, it could become a real problem, if the actions might block for some time. 
  
  
A different approach (but a bit more complicated and restricted) would be to let the Actor handle the sequential scheduling of provided async operations:  
  
Act(Func
&lt;tstate,&gt;
 action)
  
  
I.e. the caller queues delegates, which returns a Task. The Act function just ensures that each scheduled Task continues with the next. It is not possible to queue Task directly (skipping the delegate), since that would force callers to Start task at the time of the call to Act(). The delegate allows Act() to trigger the async operation when the previous Task is done.
  
  
The caller can implement efficient async operations, which do not block threads, e.g. by using Task.FromAsync() on BeginX/EndX functions and use the Actor to have them run in sequence. The caller can still queue inefficient blocking tasks when only sync operations are available.  
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment20</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment20</guid><pubDate>Thu, 05 May 2011 09:44:35 GMT</pubDate></item><item><title>x4m commented on A minimal actor framework</title><description>Thread1 is doing
  
private void ExecuteActions()
  
    {
  
        Action
&lt;tstate action;
  
        while (actions.TryDequeue(out action))
  
        {
  
            action(State);
  
        }
  
Then Thread 2 Is Doing
  
public void Act(Action
&lt;tstate action)
  
    {
  
        actions.Enqueue(action);
  
  
        if (activeTask != null) 
  
            return;
  
Then Thread 1 leaves one action in queue
  
        lock(this)
  
        {
  
            activeTask = null;
  
        }
  
I'd write something like this
  
private void ExecuteActions()
  
    {
  
while(activeTask)
  
{
  
        Action
&lt;tstate action;
  
        while (actions.TryDequeue(out action))
  
        {
  
            action(State);
  
        }
  
        lock(this)
  
        {
  
if(!queue.Empty)
  
            activeTask = null;
  
        }
  
}
  
    }
  
  
  
  
&gt;</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment19</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment19</guid><pubDate>Thu, 05 May 2011 08:42:57 GMT</pubDate></item><item><title>x4m commented on A minimal actor framework</title><description>One action can hold not runned, because you acquire lock after testing queue is empty in ExecuteActions()
  
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment18</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment18</guid><pubDate>Thu, 05 May 2011 08:31:38 GMT</pubDate></item><item><title>Anthony commented on A minimal actor framework</title><description>Retlang is a great, simple framework to handle this kind of thing:
  
  
[http://code.google.com/p/retlang/](http://code.google.com/p/retlang/)</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment17</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment17</guid><pubDate>Wed, 04 May 2011 18:27:52 GMT</pubDate></item><item><title>Rabo commented on A minimal actor framework</title><description>I'd improve it by writing it in F# as a MailboxProcessor. I guess Colin already mentioned this, but it would require hardly any code and would be perfectly suited to such a task.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment16</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment16</guid><pubDate>Wed, 04 May 2011 15:47:53 GMT</pubDate></item><item><title>Rafal commented on A minimal actor framework</title><description>You have no error handling
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment15</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment15</guid><pubDate>Wed, 04 May 2011 12:56:05 GMT</pubDate></item><item><title>Oğuzhan Eren commented on A minimal actor framework</title><description>"actions.Enqueue(action);" process should be separete Act function so I will be add action to Queue  any time (working actor)
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment14</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment14</guid><pubDate>Wed, 04 May 2011 12:28:38 GMT</pubDate></item><item><title>Colin commented on A minimal actor framework</title><description>Have you considered wrapping the MailboxProcessor&lt;'a&gt; from the FSharp Control primitives in a C# friendly type with the API you wish to define. I have done this in the project I am currently working on and it works well, although it puts a dependency on Fsharp.Core something you may wish to avoid 
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment13</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment13</guid><pubDate>Wed, 04 May 2011 12:23:50 GMT</pubDate></item><item><title>Mayrc Mellow commented on A minimal actor framework</title><description>I see a problem: if I call Act method and activeTask object isn't null, the task that I'm adding only will execute on next time that I call Act method again. Is this a problem?
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment12</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment12</guid><pubDate>Wed, 04 May 2011 12:03:06 GMT</pubDate></item><item><title>Ayende Rahien commented on A minimal actor framework</title><description>Sam,
  
No, one after another
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment11</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment11</guid><pubDate>Wed, 04 May 2011 10:42:44 GMT</pubDate></item><item><title>Sam Leitch commented on A minimal actor framework</title><description>By synchronous, so you mean each action has to execute in the same thread? If that's the case then...well... there are problems. StartNew is not guaranteed to use the same thread twice.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment10</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment10</guid><pubDate>Wed, 04 May 2011 10:34:49 GMT</pubDate></item><item><title>Sam Leitch commented on A minimal actor framework</title><description>You would need a SchedulerPair per "actor". Each ExclusiveScheduler can run in parallel (at least I hope so). I see it as a non-blocking form of reader/writer lock.
  
  
It doesn't ensure in-order processing though. Only that each task will run on its own.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment9</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment9</guid><pubDate>Wed, 04 May 2011 10:24:25 GMT</pubDate></item><item><title>Ayende Rahien commented on A minimal actor framework</title><description>Sam,
  
That means that everything in sync, but I want parallelism between different actors.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment8</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment8</guid><pubDate>Wed, 04 May 2011 10:18:37 GMT</pubDate></item><item><title>Sam Leitch commented on A minimal actor framework</title><description>Have you taken a look at the ConcurrentExclusiveSchedulerPair included in TPL Dataflow? It provides the same synchronization of tasks but doesn't break the task/continuation pattern.
  
  
Just schedule everything on the ExclusiveScheduler and you're good to go.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment7</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment7</guid><pubDate>Wed, 04 May 2011 10:14:55 GMT</pubDate></item><item><title>Scooletz commented on A minimal actor framework</title><description>How about having one ConcurrentuQueue per connection, wrapped in write-only-interface, being passed as a Actor
&lt;tstate parameter. This meets anty-requirement which allows to interrupt one actor messages with other actors'. If so, the thread would be started in the same manner (one per a concurrent queue), but it would be more explicit about having it all done on one connection., one queue.
&gt;</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment6</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment6</guid><pubDate>Wed, 04 May 2011 10:03:57 GMT</pubDate></item><item><title>tobi commented on A minimal actor framework</title><description>The queue is unbounded.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment5</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment5</guid><pubDate>Wed, 04 May 2011 09:47:27 GMT</pubDate></item><item><title>Patrick Huizinga commented on A minimal actor framework</title><description>State shouldn't be public. It should only be editable from the activeTask thread.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment4</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment4</guid><pubDate>Wed, 04 May 2011 09:27:35 GMT</pubDate></item><item><title>Ayende Rahien commented on A minimal actor framework</title><description>Tobi,
  
Great that you spotted that!
  
What else? Look for design issues.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment3</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment3</guid><pubDate>Wed, 04 May 2011 09:22:31 GMT</pubDate></item><item><title>Idsa commented on A minimal actor framework</title><description>lock (this) is not a good idea
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment2</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment2</guid><pubDate>Wed, 04 May 2011 09:18:26 GMT</pubDate></item><item><title>tobi commented on A minimal actor framework</title><description>It has a bug. The task could be just before "activeTask = null;" and the Act method could still exit due to "if (activeTask != null)" being true. A new task would not be started.
</description><link>http://ayende.com/4831/a-minimal-actor-framework#comment1</link><guid>http://ayende.com/4831/a-minimal-actor-framework#comment1</guid><pubDate>Wed, 04 May 2011 09:15:49 GMT</pubDate></item></channel></rss>