I am a student, currently studying operating system's concurrency - semaphore. I read books and read articles about semaphores, mutex & semaphores... but can't seem to answer title's condition.
There exists a semaphore, and semaphore can be used as "Binary semaphore" and "Counting semaphore" which is classified by initial value. I understand binary semaphore can prevent race condition by acting similarly as mutex(but two are not the same by various reasons.)
What i am curious about is that when we initialize the semaphore's value of more than or equal to 2, let's say n, then n values can enter the critical session. Then does this use of semaphore cause race condition?
I read articles about counting semaphores and it is considered that they are considered to keep track of the access to resources, and I'm confused about do we not use counting semaphore like this, and is counting semaphore not used to solve concurrency problems?
added below because my questions weren't detailed.
For example, when there are 100 threads, and I initialize X=10, then initialize semaphore with sem_init(&s, 0, X), and if there is a critical session in threads' code flow, then doesn't it induce race condition because 10 threads are allowed to use resources and do through the threads' flow?