Microsoft Open Sources P
Written by Kay Ewbank   
Monday, 17 October 2016

Microsoft has made P, its event-driven programming language, open source. P is designed to give developers a way to write safe asynchronous event-driven programs.

P lets you specify the system as a collection of interacting state machines, which communicate with each other using events.

p

It unifies modeling and programming into one activity, and has been used to implement and validate the USB device driver stack that ships with Microsoft Windows 8 and Windows Phone. Microsoft says that P is suitable for the design and implementation of networked, embedded, and distributed systems. 

The finite state machines in your programs each have an input queue, states, a machine-local store, and the ability to send asynchronous messages to the other state machines in your program.

P was designed to provide language primitives to succinctly and precisely capture protocols that are inherent to communication among components in asynchronous systems. The state machines run concurrently with each other, each executing an event handling loop that dequeues a message from the input queue, examines the local store, and can execute a sequence of operations. Each operation either updates the local store, sends messages to other machines, or creates new machines.

The demo video below shows P being used to control a quadcopter:

 

 

Discussing the Windows 8 USB device driver stack designed using P, the developers say that the resulting driver is more reliable and performs better than its prior incarnation (which did not use P). They say that using P allowed the developers:

"to serialize the large number of uncoordinated events coming in from hardware, operating system, function drivers and other driver components."

The event handling was more reliable and faster. The new hub driver provides a superset of the functionality of the old hub driver. In terms of reliability, synchronization issues and crashes have decreased to the point where the the number of crashes in the new USB hub driver due to invalid memory accesses and race conditions is insignificant.

In terms of performance, average enumeration time for a USB device is 30% faster, and the developers haven't seen any instances of worker item starvation that used to be apparent with the old hub driver.

Microsoft has also developed a P compiler that outputs a Zing model to enable systematic testing. The compiler also generates C code that can be used in a C compiler for execution. This is required since, as P is a domain-specific language for implementing protocols in an asynchronous application, parts of the application other than the protocols would be written in a host language such as C. The P manual describes the foreign code interface used for interoperability between P code and foreign code written in C. 

P is now available on Github.

p

More Information

P On Github 

Microsoft Research Paper On P 

Related Articles

Managing Asynchronous Code - Callbacks, Promises & Async/Await

What Is Asynchronous Programming?

Task.js Asynchronous Tasks In JavaScript

JavaScript Web Workers

Chaining - Fluent Interfaces In JavaScript

Why await? Why not multithread the UI?

Being threadsafe - an introduction to the pitfalls of parallelism

The Perils of the C# Parallel For 

Async, Await and the UI problem

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter,subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin

 

Banner


Google Kills Webmaster Central Comments
14/01/2019

This isn't "big" news but it is ironic. Google has few enough ways of engaging with the public - could it be that closing down comments is just another way to avoid having to deal with complaints and  [ ... ]



Coursera and SAS Offer Specialization
10/01/2019

A new specialization that seeks to address the shortage of professionals with data analytical skills has just launched on the Coursera platform. It comprises three courses from SAS taking students fro [ ... ]


More News

 

Python

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 17 October 2016 )