Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB programmers, allows one to declare generic concurrency abstractions and provides more natural support for inheritance. CB also offers open extensibility based on custom attributes.
Here is the simplest interesting example of Concurrent Basic, a module declaring an unbounded string buffer:
Public Asynchronous Put(ByVal s As String)
Public Synchronous Take() As String
Private Function CaseTakeAndPut(ByVal s As String) As String _
When Take, Put
This example shows all new keywords used by Concurrent Basic: Asynchronous, Synchronous and When.
This module declares two channels: an asynchronous channel, Put(s), which takes a string argument and (like all asynchronous methods) returns no result; and a synchronous channel, Take(), which takes no arguments but returns a string. The private method CaseTakeAndPut is the continuation of a join pattern that can run only when both the Take and Put methods have been called.
Now assume that several producer and consumer threads wish to communicate via the Buffer module. Producers make calls to Buffer.Put(s), which, since the channel is asynchronous, never block. Consumers make calls to Buffer.Take(), which, since the channel is synchronous, will block until or unless there is a matching call to Buffer.Put(s). Once Buffer has received both a Put(s) and a Take() the body of CaseTakeAndPut can run, returning the actual argument s of Put as the result of the call to Take. Since this is the only applicable pattern, a caller of Take will wait until\unless a call to Put has arrived.
For more information, read the paper or slides on Concurrent Basic presented at OOPSLA'08, or watch the Channel 9 video. Concurrent Basic extends previous work on Polyphonic C#, Cω and the Joins Concurrency Library.
Thanks to Erik Meijer for suggesting and encouraging me to look at VB and Lucian Wischik for getting it all to work in VB10. Early contributers were Harish Kantamneni and Danny van Velzen. Special thanks goes to Nick Benton for most of the examples and Nick Benton, Luca Cardelli, Cedric Fournet and Georges Gonthier for the underlying concurrency model.