OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Optimizing Custom Double Release Lock and Semaphore in Python asyncio

  • Thread starter Thread starter selah
  • Start date Start date
S

selah

Guest
I am currently working on a project involving file operations that need to be handled by multiple processors concurrently, but not by other threads simultaneously. For this, I've devised a concept called a Double Release Lock and a Double Release Semaphore, implemented using Python's asyncio. The key idea here is that pairs of two processors are somewhat synchronized by means of the lock and semaphore. Hence why they should only unlock or release after two release calls instead of one. This ensures that two processors can read a file at the same time, and it limits the number of processors operating simultaneously.

What I have implemented:​

  1. Double Release Lock: This lock is designed to ensure that it only becomes available (unlocked) after two release() calls have been made. This is used when two processors are to read the same file before its modified by the next processors.
  2. Double Release Semaphore: Similar to the lock, this semaphore is meant to manage access with a slightly broader scope. It allows a certain number of tasks to enter, but each task must signal completion twice before it is considered truly complete, effectively doubling the release requirement.

Questions:​

  1. Are there better alternatives to achieve the same functionality, perhaps using existing libraries or different synchronization primitives?
  2. Could these mechanisms face any potential issues under high concurrency scenarios?

I am looking for insights or suggestions on how to refine or validate this approach, or if there are alternative strategies that might be more effective or safer in terms of concurrency handling.
<p>I am currently working on a project involving file operations that need to be handled by multiple processors concurrently, but not by other threads simultaneously. For this, I've devised a concept called a Double Release Lock and a Double Release Semaphore, implemented using Python's asyncio. The key idea here is that pairs of two processors are somewhat synchronized by means of the lock and semaphore. Hence why they should only unlock or release after two release calls instead of one. This ensures that two processors can read a file at the same time, and it limits the number of processors operating simultaneously.</p>
<h1>What I have implemented:</h1>
<ol>
<li><strong>Double Release Lock</strong>: This lock is designed to ensure that it only becomes available (unlocked) after two <code>release()</code> calls have been made. This is used when two processors are to read the same file before its modified by the next processors.</li>
<li><strong>Double Release Semaphore</strong>: Similar to the lock, this semaphore is meant to manage access with a slightly broader scope. It allows a certain number of tasks to enter, but each task must signal completion twice before it is considered truly complete, effectively doubling the release requirement.</li>
</ol>
<h1>Questions:</h1>
<ol>
<li>Are there better alternatives to achieve the same functionality, perhaps using existing libraries or different synchronization primitives?</li>
<li>Could these mechanisms face any potential issues under high concurrency scenarios?</li>
</ol>
<p>I am looking for insights or suggestions on how to refine or validate this approach, or if there are alternative strategies that might be more effective or safer in terms of concurrency handling.</p>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top