Racing, trying a lock
Description:
This kata is part of the series about race conditions. The description describes a general case and is the same for all laps.
Story
Lap {1}{2}{3}{4}{5}...
A race condition, loosely speaking, is a situation when the order of some actions isn't specified, but the output of a program depends on it. Here is a code that has race condition problem and you should prove it.
Formal problem
Test cases section contain Race
class which implements one or more public methods returning a stream (IEnumerable<int>
). Whenever new value of returned stream is requested (via MoveNext()
method of enumerator), the method itself runs until next yield return
instruction.Kata
class implements a number of methods named ParallelN
(where N varies).
Each Kata.ParallelN
method represents certain usage case of Race
class in parallel computation, where Kata
class effectively works as sheduler.
Input:Kata.ParallelN
methods recieve a number of enumerators of streams returned by Race
methods. These enumerators are already set on first elements of corresponding streams. Check test cases section to see details.
In at least one of Kata.ParallelN
methods there is a way to order operations so that result is "unexpected" in some way. It may be code giving wrong answer, or Race
class invariant being ruined, or some operations performed in wrong order. Find and exploit it.
Notes and hints
-- For C#, documentation on stream mechanism: IEnumerable, IEnumerator.
-- Wiki article: race condition.
-- Tests contain only one actual test, which in turn runs several usage scenarios and checks if any of them led to unexpected results.
-- Enumerators have a number of line where corresponding code has stopped in Current
field.
Credits
Similar Kata:
Stats:
Created | May 21, 2015 |
Warriors Trained | 31 |
Total Skips | 33 |
Total Code Submissions | 7 |
Total Times Completed | 6 |
C# Completions | 6 |
Total Stars | 0 |
% of votes with a positive feedback rating | 0% of 0 |
Total "Very Satisfied" Votes | 2 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |