Converting Synchronization Primitives in C/C++ to P #450
-
For larger and faster adoption of P Programming, tutorials on following topics would be very helpful.
I have been struggling to get my folks to use P because everyone is trying to map in their minds these primitives to P and we don't know if we have a good conversion documentations/videos. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Anup, Thanks for these questions. Here is a simple example that models lock-based shared object and read-write lock based shared objects in P: https://github.com/p-org/P/blob/master/Tutorial/Common/SharedMemory/PTst/TestRWLBSharedObject.p RWLock: https://github.com/p-org/P/blob/master/Tutorial/Common/SharedMemory/PSrc/RWLBSharedObject.p The way to think about it is that one can model shared memory using message passing, all synchronization (using locks) that happens in shared memory programs can be mimicked using shared memory underneath. So if you look at: https://github.com/p-org/P/blob/master/Tutorial/Common/SharedMemory/PTst/TestRWLBSharedObject.p. The Acquire functions under the hood perform message passing. I agree that a better example would help here and I will definitely add it to the tutorials. Thanks! Please let me know your comments. |
Beta Was this translation helpful? Give feedback.
Thanks Ankush! We will go through the example you mentioned.
Basically we need "dumb" synchronization examples to learn from. Take any concurreny book (c++/Java, c), converting the first 10 solved concurrent problems from it to P would be a great tutorial.
I also had the following questions:
1# What's a atomic step in P programming? What's the smallest default atomic?
Like if X is a integer, would the following be considered atomic?
X = X + 1
From example in pluscal, every step is atomic. Step is defined by labels. Following is a note from lamport.
"PlusCal is an algorithm language. Execution of an algorithm consists of a sequence of steps. An algorithm’s computational complexity is the n…