You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/11/30 09:01:27 UTC

[GitHub] [ignite] aarmam opened a new issue, #10409: Ignite semaphore release vs. close

aarmam opened a new issue, #10409:
URL: https://github.com/apache/ignite/issues/10409

   Hi, 
   I have a question about race condition on closing semaphores. As I understand semaphores are not removed automatically and must therfore be closed manually. Lets say two threads want to change some object and try to aquire semaphore for it: 
   
   ```java
   IgniteSemaphore semaphore = ignite.semaphore(objectId, 1, true, true);
   if (semaphore.tryAcquire(5, TimeUnit.SECONDS)) {
       try {
           changeObject(objectId);
       } finally {
           semaphore.release(); // First thread releases semaphore
           // Second thread aquires semaphore
           semaphore.close(); // First thread closes semaphore
       }
   }
   ```
   1) What happens if first thread tries to close semaphore while second thread has aquired it?
   2) But my main quiestion is - can I close the semaphote without calling release before it? So second thread cannot aquire it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] aarmam commented on issue #10409: Ignite semaphore release vs. close

Posted by GitBox <gi...@apache.org>.
aarmam commented on issue #10409:
URL: https://github.com/apache/ignite/issues/10409#issuecomment-1331871201

   > In most cases you don't want to close a semaphore. You create it once and reuse.
   Yes but in our case the changed object is relatively short lived and therefore aquired semaphore is always with unique id.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] ptupitsyn commented on issue #10409: Ignite semaphore release vs. close

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on issue #10409:
URL: https://github.com/apache/ignite/issues/10409#issuecomment-1331861534

   1. It will be closed and removed from the cluster, even if acquired by other threads.
   2. Yes, you can close without releasing.
   
   In most cases you don't want to close a semaphore. You create it once and reuse.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] aarmam closed issue #10409: Ignite semaphore release vs. close

Posted by GitBox <gi...@apache.org>.
aarmam closed issue #10409: Ignite semaphore release vs. close
URL: https://github.com/apache/ignite/issues/10409


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org