← Back to Challenges / Challenge #3

Race Condition in Counter Service

★★★★☆
📁 rails/rails 🔢 ghi9012 Concurrency
★★★★☆
Difficulty
+150 XP reward
file.js
1 class Counter { • Line 12: Same issue with decrement operation
2 constructor() {
3 this.value = 0;
4 }
5
6 increment() {
7 this.value = this.value + 1; • Race condition when increment called concurrently
8 return this.value;
9 }
10
11 decrement() {
12 this.value = this.value - 1; • Same issue with decrement operation
13 return this.value;
14 }
15 }

Hints:

  • Line 7: Race condition when increment called concurrently
  • Line 12: Same issue with decrement operation
  • No synchronization mechanism for thread safety

Submit Your Fix

Lines marked: 0

Click a marked line number below to edit its fix.

Click on lines in the diff above to mark them, then add your fixes here.