Back to course home
0% completed
3. Semaphore
In this example, we focus on a shared variable named counter, which is accessed by several threads at the same time. We create 10 threads for this task. Each thread works to increase the counter value, but only 5 threads are allowed to do this at the same time. This limit of 5 is set by a semaphore. The goal is for the counter to reach a specific number, called TARGET_VALUE, which is 5000 in our case.
Here are the main points of this setup:
- We use a semaphore to control how many threads can increase the counter at one time. In our program, up to 5 threads can do this simultaneously.
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible