Introduced
Concurrency and coordinated Runtime (concurrency and Coordination RUNTIME,CCR) is an asynchronous messaging class library on a. NET platform that provides a small, powerful foundation for organizing applications in different ways. Applications can get better responsiveness and better scalability and fault tolerance by effectively using CCR. The most amazing thing about it is that developers get these conveniences while also reducing (or even completely eliminating) direct manipulation (or trapping errors) of threads, locks, mutexes, or other synchronization elements.
If your application is single-threaded, CCR can make your programs more responsive and take full advantage of the CPU core-while keeping your code base conceptually clean. If your program has multiple threads enabled, CCR can maintain (and even improve) the throughput of your programs while simplifying your code base.
In short, CCR provides the following features:
A simple and high-performance message delivery implementation. Use very lightweight and type-safe channels to connect objects in an action-oriented perspective.
A set of basic scheduling constraints. Scheduling is almost all of CCR. You can create tasks, pass messages to other components in the process, and process the request by declaring some constraints with objects called Arbitrators (arbiter). CCR can ensure that these constraints are met before executing your code.
Provides a better model for failure handling. CCR provides "causality", meaning that it provides a context for a series of related asynchronous subtasks, such that a failure, such as throwing an exception, can be isolated in isolation, which is not related to the thread that initiated the task.
Better use of existing (or future) computing power. CCR can use the existing thread pool for scheduling, and if you need it, you can use its own implementation, which in some cases can lead to better performance. Naturally, this mechanism will only have a subtle effect on your code.
Simplifies the asynchronous IO operation. The key to increasing the scalability and performance of stand-alone processes is ultimately due to efficient I/O-intensive operations. I/o-intensive operations are often many times slower than compute-intensive operations, and a blocked I/O operation wastes Valid resources (in this case, threads) so that they cannot handle other waiting tasks. asynchronous I/O operations allow these resources to be freed to handle other tasks until I/O operations are complete. However, a series of asynchronous operations need to separate their "start" and "Finish", which makes coding much more difficult. CCR is implemented using a special C # iterator that enables developers to easily control such operations.
Through the asynchronous messaging mechanism, our component communicates with another component by sending data, and it is worth mentioning that there is no temporary relationship between the data and subsequent replies. A sent message may need to be processed at some point in the future, and only then will the message be answered.
This asynchronous messaging model is the basis for most cases of cross process (inter-process) computing, but compared to the fact that using CCR in a real-world application for pure process internal (intra-process) communication can often be better guaranteed, Unlike the former, they can fail in many cases. Therefore, CCR can be used not only for low-level I/O operations, but also for building scalable distributed systems.
The underlying type of CCR
CCR consists of several base types:
Task: Any piece of code that is used for execution.
Task Queue (Taskqueue): Exactly, "distribution queue (DispatcherQueue)." A list of tasks to be performed. Threads from a CLR thread pool or a CCR thread pool (that is, dispatcher) take the task out of the queue and execute it.
Port: A message queue within a process that connects components. In short, this is just a list (linked-list) where the generator places messages within the port. CCR provides generic overloads that provide type-safe operations.
Arbitrator (arbiters): The underlying element of CCR, which connects ports and tasks. They define constraints that determine the tasks that need to be created after the message arrives at the port, and which task queue to use to accept. A variety of arbitrators are built into CCR, most of which can be combined to achieve more flexible functionality.
Having learned these basic concepts, let's look at some simple CCR code. First, let's define a simple C # console application that will run all of the examples. Note that in this program, we use the CCR custom thread pool (Dispatcher) and bind to our task queues. This means that the tasks in the queue are executed by threads in the custom thread pool.
static void Main(string[] args)
{
using (var dr = new Dispatcher())
{
using (var taskQueue = new DispatcherQueue("samples", dr))
{
// Examples will go here...
// Need a blocking call to prevent the application
// exiting.
Console.ReadLine();
}
}
}