Concurrency checkpoint
Challenge on lesson: Checkpoint: concurrency
CHALLENGE
Difficulty: advanced+25 XP
Fix the counter race: implement static long CountUnique(int[] values) returning the count of distinct values using a ConcurrentDictionary as an atomic set โ the test hammers it from 8 parallel tasks to prove there is no lost-update. Then implement static bool TryAddIfAbsent(ConcurrentDictionary<string,int> d, string key, Func<string,int> compute) that atomically adds a computed value ONLY if the key is absent โ and never re-runs compute after the key exists: repeat calls return false WITHOUT invoking the factory.
Press Submit to check your solution.
Back to lesson: Checkpoint: concurrency