Mutex icon indicating copy to clipboard operation
Mutex copied to clipboard

Enhance livelock example

Open KLarpen opened this issue 2 years ago • 0 comments

In the video chapter related to 3-livelock.js example there is no clear evidence what livelock is and how you may notice it by that example. Had noticed in the comment section that I'm not the only one who mention that.

Current 3-livelock.js example in this repository contains looping recursion that useless by code itself. In other words there is no state that you may compare as normal working processes in difference to livelock.

I propose to extend usage example. It becomes more complex but clear to notice livelock and test the difference:

  • 7 threads
  • 6 of it executes high frequency loop (the same as in the current repository state)
  • last 7th thread executes low frequency loop with long running process (being long running isn't necessary but that way more easy to notice the complete execution of it)
  • initial 10 times frequency difference do not lead to livelock (at least on the level between high and low frequency processes, excluding the possibility of livelock among 6 high frequency ones)
  • comment with proposal to make frequency difference 100 times higher which will lead to livelock on both levels (possible highFrequencyLoop inconsistency and starvation of the lowFrequencyLoop).

Please review my proposal because I'm not an expert in parallel programming. The articles on the topic of livelock in the internet are quite confusing and controversial. The most well explained that I've found is Deadlock, Livelock and Starvation. I'm trying to figure out how to make more clear and evident test but realizes that my understanding might be wrong.

KLarpen avatar Feb 14 '23 16:02 KLarpen