Comments (6)
Hi @oberstet, this is an excellent question.
A way to think about it is that each state machine is executing concurrently and the only shared state in the system (for which there can be race condition) is the inbox or message buffers. So, when any event handler in any state machine is executed, then yield
or scheduling
points are only inserted just before each send and receive operation so that the scheduler can interleave all sends and receives. Everything else thats executed between these sends is atomic as it only accesses local state.
Does this help?
from p.
That way we can represent race conditions.
fwiw, the way that I look at this is: if I want to model realistically (eg a backend DB transaction is atomic, but not spanning a client message delivery) OR if I want to model an implementation in a "modern" programming language supporting asynchronous programming (eg. with futures/deferreds/promises or coroutines) then each "await/yield" point must be modeled as potentially branching into a new state sequence.
having a separate state machine for each asynchronous synchronization / branching point seems "wrong" .. that's my question - is it wrong? Do I fundamentally misunderstand P?
from p.
then
yield
orscheduling
points are only inserted just before each send and receive operation so that the scheduler can interleave all sends and receives
yes, that clarifies the semantics for me, thanks! I can see the systematic/symmetry in this design. unfortunately, that's what I did suspect:( as the consequence is:
in an asynchronous program, every yield/await is a scheduling point, an independently scheduled continuation. the entry point to such a task/coroutine is a scheduling point, as is the return point. and while the latter 2 map nicely to state machine message handler entry and send message calls, the former is more general:
asynchronous continuation context can be nested, and this must be mapped to 1 state machine per asynchronous continuation context and message passing for yield/await.
eg in the "1_ClientServer" tutorial example, one would need more state machines to separate out the DB transaction and the sending of the client reply. separate from consuming a request from the inbox of the main server FSM.
practically, with such an application, stuff like this can happen:
- the app backend sent the DB transaction, but the backend crashes before receiving a DB reply
- the DB at this point now might or might not have committed
- likewise, once a DB commit success was received in the app backend, the backend might send the client reply, and before the client receives the reply, the client crashes
- ...
anyways. it'll depend I guess. however, looking from this "async app programming" perspective, I am wondering:
what I really need to exhaustively explore all possible state sequences of an async single-threaded app implementation would be: automatically use every future/promise/deferred/coroutine as a scheduling point.
those are exactly the branching points in the state sequence of such a program. wrt to the event loop / reactor (the "green threads" scheduler), not the OS of course. OS scheduling adds more branch points.
from p.
I should probably add: I am mostly socialized in the context of monolithic kernels with mostly blocking system calls, and then using a green threads user program scheduler with async/await or the like. and then create a distributed app using instances of such a program.
IOW: never used microkernels, and though I have used purely message passing systems such as Erlang/OTP and purely functional (monadic IO) languages in the past, I have mostly moved to async/await style which "seems more natural".
Yeah, I know, I am not believing hard enough;) If I try very very hard, I can think about programs as just sets of assertions. Well, it seems my patience for such brain puzzles is getting lesser the older I get;) Doesn't feel natural. For me. Anyways, just my 2cts being a regular programmer ..
from p.
then
yield
orscheduling
points are only inserted just before each send and receive operation so that the scheduler can interleave all sends and receives
just rethinking this: actually, one should be able to create a devnull
process that throws away every message it receives, and then just use send(devnull)
to effectively yield/await
at any point within an event handler?
from p.
You can yield/await
within an event handler using the receive
statement in P. Which is similar to await
in C#.
https://p-org.github.io/P/manual/statements/#receive
Not sure if this is what you are hinting towards in your last message?
from p.
Related Issues (20)
- [Tutorial] Redundant conditional in the EspressoMachine tutorial HOT 5
- `case` in `receive` - `case`syntax requires an argument even if the event doesn't have one HOT 1
- Compiling 1_ClientServer gives me error NU3037 on macOS HOT 5
- Simplify the process of writing test cases.
- Simplify the module system requirements
- Add support for collection union for sets
- Adding Probabilistic Choose() in P
- Emacs support for editing P files HOT 2
- VSCode extension syntax highlighting not working HOT 2
- Tutorial - Client/Server - Error: "'PMonitor' does not contain a definition for 'TryRandom'" HOT 2
- Tutorial - "Error: Failed to get test method '' from assembly 'ClientServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' " HOT 4
- Installation instructions should say you need nuget as a dotnet source HOT 1
- Grammar railroad diagram HOT 1
- [docs] compositional programming: docs and examples? HOT 1
- `GuaranteedWithDrawProgress` in Tutorial 1 is inaccurate/misdocumented HOT 4
- Internal Error: No such file or directory HOT 1
- In trace logs enums are printed as integers and its annoying!
- Unable to compile due to "no viable alternative at input" HOT 9
- Infinite loop in Timer module HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p.