Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 706289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:08:57+00:00 2026-05-14T04:08:57+00:00

I have to simulate a game where each player has turns and needs to

  • 0

I have to simulate a game where each player has turns and needs to ‘pay attention’ to what’s going on.

So far, I know I’ll need two threads for each player, one that will sleep until the player’s turn and the other paying attention.

My question is: Should I work each player as a ‘fork’ and the threads on the fork, or just create some threads for the player and associate them somehow?

It’s the first time I’ve worked with concurrency, semaphores and threads so I’m not sure about the good practices and programming style.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:08:58+00:00Added an answer on May 14, 2026 at 4:08 am

    You’ve stumbled onto the edges of a huge religious war, revolving around the question

    Should event-driven programs be written using multiple threads or using a single event loop?

    The threads camp believes that individual entities, like “players”, are more easily programmed when written as actual threads, possibly explcitly giving up the processor when they no longer need it. Information about the player’s state can be stored in local variables and even in the program counter. But with threads you may have to worry about atomicity, deadlock, and the other joys of concurrent programming.

    The event-driven camp believes that it’s much simpler to get an entire application right when every entity is capable of responding to every event, and that entity gets total control of the processor for the amount of time it needs to process the event (which had better be finite, and usually had better be short). There are no worries about concurrency because every event handler executes atomically, but there is a programming cost: when the event handler finishes, all its procedures exit, and so information about its state has to be stored in the fields of an object allocated on the heap.

    The threads story tends to shine when an entity has complex control flow or wants to use a lot of abstraction—both of these are hard to code without threads. The events story tends to shine when handlers are fairly simple—it’s great having every handler execute atomically without having to worry about it, and it simplifies communication between entities.

    Before proceeding with your assignment, find out to which religious group your instructor belongs.

    Since you’ve asked about threads, I highly recommend the threads and channels libraries in Dave Hanson’s C Interfaces and Implementations. The software is free, and the book is worth buying—it includes many other modules that will be incredibly useful to anyone writing homework assignments in C.

    Should I work each player as a ‘fork’ and the threads on the fork, or just create some threads for the player and associate them somehow?

    Unless you’ve been asked to use fork, I’d avoid it—the mechanisms for communicating between Unix processes are not that pleasant to use. If you can get the Hanson library, I’d say create a thread per player, and have the players communicate with each other (and with the game server, which should also be a thread) using Hanson’s channels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started testing my UI using qUnit, so I need to simulate some
I have a probability problem, which I need to simulate in a reasonable amount
I have a number of tables that use the trigger/sequence column to simulate auto_increment
I have a simple function written in Oracle 9i (version 9.2.0.4.0) to simulate an
In an online manager game (like Hattrick ), I want to simulate matches between
I'm trying to simulate keyboard commands for a custom game controller application. Because I'll
Do we have a way to simulate a webcam driver, that will provide realtime
I'm trying to simulate a mouse click on a window. I currently have success
I have a program meant to simulate some probability problem (A variation of the
Is it possible to simulate user input in android ? For example to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.