October 21, 2024
Chicago 12, Melborne City, USA
python

Can we use Preemptive Resource with a Container in simpy?


I’m working on a simulation working with simpy where i’ve a class like this:

class memory:
    def __init__(self, env: Environment, size: int, memory_name: str):
        """Instantiation function

        Args:
        env (Environment): simpy environment
        size (int): Size of memory
        """
        self.is_accessed = PreemptiveResource(env, 1)
        self.container: Container = Container(env, size, size)
    


My goal is to access the variable self.container with some priority but i don’t want to block the other process to try accessing it.
By that i mean. I’ll have several process with level 1,2 or 3 of priority. which can access the container. And it’s only when the process ask for too much that i’d need to prioritize.
If i block the access with :

with self.is_accessed.request(my_prioritie, True) as access:
    self.container.get(value)

It block also another process to access the container even if there is still place in the container.
Do you see other ways?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video