Hello guys,
I have to implement the Peterson's algorithm in java.
For who of you which is not aware about it, is a low level concurrency solution for two threads
that want to use a shared resource.
The algorithm use three variables, two flags (booleans) and a turn
indicator (usually implemented as an int, but possibly a boolean would
work as well).
More information about the algorithm here : http://en.wikipedia.org/wiki/Peterson's_algorithm
Now, is really easy to implement it and in theory I won't need to use
any synchronization
construct available in java (such as synchronized keyword) since the
shared memory should be enough.
Here comes my problem : I learned that some hardware system don't
necessarily execute the instructions
in a FIFO order, such as, they don't execute necessarily instructions
in the same order as they are written in the source code (and then
compiled) to improve efficency.
All this in a standard sequencial program (not concurrent).
Such hardware, to support concurrency, has special "atomic" instrucion
such as test & set.
What about the jvm ?
Because if this is the case (such as execution of the instructions not
in a sequencial way), the instructions in my program could be executed
in an order that is not the one I wrote it that will eventually result
in an invalid state of the program.
Thank you for any information.
Hello from 2020! Not sure if this will reach you, but just wanted
to say that this whole thread discussion is helping me out in one
of my assignments 14 years down the road! :D
Hi,
On 28/07/2020 8:23 am, dipanseshagiri@gmail.com wrote:
Hello from 2020! Not sure if this will reach you, but just wanted
to say that this whole thread discussion is helping me out in one
of my assignments 14 years down the road! :D
I'm not the original poster, but am curious while news server you
are using that still has message from to long ago. I'm using a
pretty rubbish one where messages expire in something like 14 days.
Makes reading long discussions or past thread impossible. :-/
I'm hoping to find a better news feed.
Regards,
Graeme
GoogleGroups, not that I would suggest them as a 'good newsfeed',
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 73:38:48 |
Calls: | 6,657 |
Calls today: | 3 |
Files: | 12,203 |
Messages: | 5,332,384 |
Posted today: | 1 |