Joins (concurrency library)
Encyclopedia
Joins is an asynchronous concurrent computing
Concurrent computing
Concurrent computing is a form of computing in which programs are designed as collections of interacting computational processes that may be executed in parallel...

 API
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 from Microsoft Research
Microsoft Research
Microsoft Research is the research division of Microsoft created in 1991 for developing various computer science ideas and integrating them into Microsoft products. It currently employs Turing Award winners C.A.R. Hoare, Butler Lampson, and Charles P...

 for the .NET Framework
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

. It is based on join calculus and makes the concurrency constructs of the Cω language available as a .NET assembly
.NET assembly
In the .NET framework, an assembly is a compiled code library used for deployment, versioning, and security. There are two types: process assemblies and library assemblies . A process assembly represents a process that will use classes defined in library assemblies...

 that any CLI compliant language can use.

Overview

Joins can be used to express concurrency in an application using the joins pattern, usable both for multi-threaded applications as well as for event based distributed
Distributed computing
Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...

 applications. The Joins API emulates declarative type-safe
Type safety
In computer science, type safety is the extent to which a programming language discourages or prevents type errors. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types...

 expression of synchronization patterns.

The Joins library emulates asynchronous and synchronous methods. An asynchronous method, in Cω and Joins parlance, is one which does not block the caller method, nor does it return any result, whereas a synchronous method blocks the caller method. In the Joins API, synchronous as well as asynchronous methods are implemented as generic
Generic programming
In a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...

 delegates
Delegate (.NET)
A delegate is a form of type-safe function pointer used by the .NET Framework. Delegates specify a method to call and optionally an object to call the method on. They are used, among other things, to implement callbacks and event listeners....

. Usage of generics provide type safety. For example, a set of synchronous and asynchronous method can be created and using them to create an object that implements the pattern, as:

public class JoinDemo
{
public readonly Asynchronous.Channel Queue;
public readonly Asynchronous.Channel Send;
public readonly Synchronous.Channel Retrieve;
private Join joinPattern = Join.Create;

public JoinDemo
{
joinPattern.Initialize(out Queue);
joinPattern.Initialize(out Send);
joinPattern.Initialize(out Retrieve);
}
}


When asynchronous methods are called, the parameters are put in a channel, which is a queue managed by the Joins runtime. The method can optionally start a new thread to process the parameters in the background, and return the results. When the corresponding synchronous method is called the parameter is returned for further processing. If no parameter is present in the queue when the synchronous method is called, the caller stalls. The Joins runtime schedules which parameter is returned based on whether it is ready.

The synchronization pattern of the methods are defined by joins patterns, which describes what happens when a set of channels are invoked. For example, what happens when Send and Retrieve are called together can be different than Send and Queue.


public void SetPatterns
{
join.When(Send).And(Retrieve).Do(delegate (string s)
{
return s;
});
join.When(Queue).And(Retrieve).Do(delegate (int n)
{
return n.ToString;
});
join.When(Send).And(Queue).And(Retrieve).Do(delegate (string s)
{
Send(s);
return Retrieve;
};
}

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK