Countdown counter

Report a typo

Here's a class named CountDownCounter. The class has a single field count. An instance of the class is used by different threads concurrently. Each thread invokes the method decrement to repeatedly decrease the field.

After the completion of all threads, the field has an incorrect value.

Fix the code so that it can work correctly with multiple threads. Do not make the class public.

Example:

Let's assume we have one instance of CountDownCounter and four threads. The initial value of count is 100000. If each thread invokes the method decrement 10000 times, after the completion of all threads, the value of count must be 60000.

Write a program in Kotlin
class CountDownCounter(var count: Int) {
fun decrement() {
count--
}
}
___

Create a free account to access the full topic