1 # Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
6 from typing import List, Optional
7 from dataclasses import dataclass
8 from argparse import ArgumentParser
11 from simgrid import Actor, Engine, Host, Semaphore, this_actor
23 sem_empty = Semaphore(1) # indicates whether the buffer is empty
24 sem_full = Semaphore(0) # indicates whether the buffer is full
28 parser = ArgumentParser()
33 help='path to the platform description'
37 type=lambda raw_words: raw_words.split(","),
38 default=["one", "two", "three"],
39 help='Comma-delimited list of words sent by the producer to the consumer'
44 def producer(words: List[str]):
45 this_actor.info("starting consuming")
46 for word in words + [END_MARKER]:
48 this_actor.sleep_for(1)
49 this_actor.info(f"Pushing '{word}'")
52 this_actor.info("Bye!")
56 this_actor.info("starting producing")
57 word: Optional[str] = None
58 while word != END_MARKER:
60 word = str(shared.buffer)
62 this_actor.info(f"Receiving '{word}'")
63 this_actor.info("Bye!")
67 settings = create_parser().parse_known_args()[0]
69 e.load_platform(settings.platform)
70 Actor.create("producer", Host.by_name("Tremblay"), producer, settings.words)
71 Actor.create("consumer", Host.by_name("Jupiter"), consumer)
75 if __name__ == "__main__":