|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.
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.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Monday, 17 October 2016 )|