I read the difference between POSIX semaphores and System V, and I read some articles about the same. In each article, this expression is written: "System V semaphores are useful if you need to implement atomic operations with several increments-decrements in one step."
My questions:
1) What is the need for multiple increment / decrease in one atomic operation? Could you explain an example?
2) Why does semop allow you to change the value to a value less than -1 and more than +1? Is there a practical use / example of the same?
(I know that using the semop () function in System V semaphores I can increase or decrease the semaphore by the specified value for one semaphore in the semaphore array and that the same cannot be done with sem_wait () or sem_post () from POSIX semaphores. But what's the point?)
The articles I read are for your reference:
1) http://www.ibm.com/developerworks/library/l-semaphore/
2) Differences between System V and Posix semaphores
3) http://www.linuxdevcenter.com/pub/a/linux/2007/05/24/semaphores-in-linux.html?page=4
4) http://linuxtips.pbworks.com/w/page/29023300/SystemV%20vs%20Posix%20IPC
UPDATE:
I read the articles below that have some mention of semaphore increment / decrement using semop (), but I still can't get an example / practical use of the same. Articles for your reference:
1) http://kaharris.org/teaching/51081/Assignments/Final/systemV.pdf
Excerpt from the article: (under the heading "Example of operations with several semaphores")
"The power of System V semaphores is that they can be used to atomically validate and install multiple semaphores in a single operation."
He gave a small excerpt from how to do this. But the practical use of the same.
2) http://www.anirudhtom.com/2011/02/system-v-semaphores-for-babies.html
The author wrote code for the multiple increment / decrement of the semaphore in an atomic operation under the heading "IMPLEMENTING SEMAFRA SETTINGS". The practical use of this is not yet mentioned here.
3) http://books.google.co.in/books?id=-Mq5ve5KHXQC&pg=PA109&lpg=PA109&dq=system+v+semaphore+multiple&source=bl&ots=SsdKqyG-Kp&sig=Y7AGqHrsOWaOk8EvCX2dH2RqEnA&hl=en&sa=X&ei=RVomVK-pIIuEuwSV0ILwBQ&ved=0CDQQ6AEwBDgU # v = onepage & q = system% 20v% 20semaphore% 20multiple & f = false
Excerpt from the book:
"On a UNIX V system, the semaphore mechanism does some tuning. The atomicity of the operation is preserved. However, the added or subtracted value of the operations can be more than one. (Why? What to use?). And even more, processes can perform several semaphore operations at the same time to avoid deadlock problems when multiple processes compete for several different resources at the same time. (How? An example?) "
I hope this issue becomes more clear.
Please comment if you have any doubts about the question asked.
Thanks in advance!
An example in which several increments / decrements may be useful: Imagine some kind of conference system where for a video session you need one channel for video and another for sound, but in other sessions only the audio channel is used. You can use semaphores to control access to channels. When a session ends, it must reduce all the semaphores that it uses immediately to free them for other sessions. If it is not atomic, a videoconference session, perhaps when it starts, will be able to capture the audio channel, but too late to also capture the video channel.
The second question is related to load balancing. By resolving values ββother than [-1.1], you can use the semaphore value as a measure of the size of the queue. In the conference example above, if the load on all local channels is very heavy, you can probably redirect the session to another, less busy trunk with your own channels.
Hope this improves a bit.
Source: https://habr.com/ru/post/1203469/More articles:How to get current loaded page URL from iframe - javascriptUICollectionView visibleCells returns 0 before scrolling - iosSitemap contains URLs blocked by robots.txt - search-engineUpdate component outside iframe - jsfHow can I check if a custom ios8 keyboard extension has public access? - iosThe best way to export a SQL Server database to sqlite (or SQL Server Compact) is .netProgrammatically get a user who locks an Excel workbook - c #Scaling in google map api 3 [ios] - javascriptThe union of several objects that use the same identifier - laravelHow to create an AST parser that makes syntax errors? - compiler-constructionAll Articles