Challenge: Dispatchers

Solve a challenge regarding dispatchers.

We'll cover the following

Problem

Write a program using dispatchers to correct the shared state problem. A variable i has to be incremented from 10,000 threads, and it should not be shared with any threads. Print the value of i after two seconds of delay. Use dispatcher in such a way that the shared state problem is resolved.

Restriction

The output will be available in the terminal.

Output

The output will be shown after two seconds of delay.

10000

Get hands-on with 1200+ tech skills courses.