Skip to content

Instantly share code, notes, and snippets.

@mihirs16
Last active May 21, 2023 21:18
Show Gist options
  • Save mihirs16/cf35fe88a13c2df63477f5b33ece7a03 to your computer and use it in GitHub Desktop.
Save mihirs16/cf35fe88a13c2df63477f5b33ece7a03 to your computer and use it in GitHub Desktop.
This is toy problem for practicing fundamentals of a programming language along with concurrency and parallelism. Inspired from a coursework by https://www.eecs.qmul.ac.uk/~pbo/

Task: You will implement an app that uses threads and concurrent computation. Your task to simulate a social network. The main program should spawn num_ants number of threads, and each of these threads model an Ant (user) in the social network. The Ants should then (at random intervals) choose one of the other Ants (at random) and send a random message to that Ant.

  • Your project should define an appropriate data type Ant, which should include their username, and a Message type to keep track of messages between ants.
  • Your project should also contain a main thread which creates num_ants "ants" (num_ants values of type Ant), and spawns num_ants threads, one for each of these ants.
  • Each user thread should behave as follows: at random time intervals, the thread should select one of the other ants at random, and send a random message to that ant.
  • Your system should simulate num_messages messages, and then terminate and output the final count of how many messages each user received.
@mihirs16
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment