Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi state machine/ MSM] execute_queued_events
From: christophe.j.henry_at_[hidden]
Date: 2014-09-25 01:52:24


>I modeled the states of a simple network communication (implemented using boost::asio) using boost::msm.
>The states are: Disconnected -> Connecting -> Idle -> Sending Message -> Waiting for Response -> Idle
>
>I have multiple threads, which use this network communication to send messages.
>While the state "Waiting for Response" is active, I cannot send any further message.
>So when a thread wants to send a message, I enqueue this in a separate queue and I read this queue only when entering state "Idle".
>The reason for the separate queue is that the transition "Waiting for Response -> Idle" can only be triggered through the boost::asio read handler.
>
>Maybe this can be done easier with your new implementation?

It will but not yet because the queue handling is missing in the lockfree part. I need some time to finish this.

Seeing the use case I think you might be using the wrong tool. What you want is not to enqueue your events in advance, what you want is to defer the event with the message until you enter Idle. You might want to have a look at deferred events.
Then for the synchronization you can just lock any calls to process_event as one of them will eventually process the deferred event too.
When I’m done with lockfree, you will simply have to remove the lock and it will work the same, just faster.

I personally have often the same to implement and I use from my upcoming boost.asynchronous library a single_thread_scheduler to serialize calls.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net