P is a programming language for asynchronous event-driven programming and Internet of things developed by Microsoft and University of California, Berkeley. P enables programmers to specify systems consisting of a collection of state machines that communicate asynchronously in terms of events. P programs can run and be analyzed on any platform supported by .NET. Additionally, P programs can generate C# and C code. P is open source, licensed under MIT License, and available on GitHub.
Example machine BankServer { var database: Database;
start state Init { entry (initialBalance: map[int, int]){ database = new Database((server = this, initialBalance = initialBalance)); goto WaitForWithdrawRequests; } }
state WaitForWithdrawRequests { on eWithDrawReq do (wReq: tWithDrawReq) { var currentBalance: int; var response: tWithDrawResp;
// read the current account balance from the database currentBalance = ReadBankBalance(database, wReq.accountId); // if there is enough money in account after withdrawal if(currentBalance - wReq.amount >= 10) { UpdateBankBalance(database, wReq.accountId, currentBalance - wReq.amount); response = (status = WITHDRAW_SUCCESS, accountId = wReq.accountId, balance = currentBalance - wReq.amount, rId = wReq.rId); } else // not enough money after withdraw { response = (status = WITHDRAW_ERROR, accountId = wReq.accountId, balance = currentBalance, rId = wReq.rId); }
// send response to the client send wReq.source, eWithDrawResp, response; } } }
See also
Microsoft Research Free software movement
References
Further reading P: Safe asynchronous event-driven programming. Ankush Desai, Vivek Gupta, Ethan Jackson, Shaz Qadeer, Sriram Rajamani, and Damien Zufferey. In Proceedings of ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), 2013. Systematic testing of asynchronous reactive systems. Ankush Desai, Shaz Qadeer, and Sanjit A. Seshia. In Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering (ESEC/FSE 2015). Building Reliable Distributed Systems With P. Ankush Desai, Ethan Jackson, Amar Phanishayee, Shaz Qadeer and Sanjit A. Seshia. University of California, Berkeley. Technical Report No. UCB/EECS-2015-198.
External links Official website Source code on GitHub P: Safe Asynchronous Event-Driven Programming P: A programming language designed for asynchrony, fault-tolerance and uncertainty


