Thread: Shared memory and semiphores, how to synchronize multiple accesses?

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    1

    Shared memory and semiphores, how to synchronize multiple accesses?

    Hello, I have to write a client/server sea battle game using shared memory and (posix) semiphores to communicate between them.

    A short description for the implementation:
    2 clients connect to the server, each client places their ships on his field and then the round-based game starts where each client selects a field on the opponents field to fire at until all ships of one client are destroyed.

    My question is:
    How do I need to set up the semiphores (and how many) to make sure that the access to the shared memory is being rotated between the 2 clients each round so one of them doesn't accidentally get to play 2 consecutive rounds?

    Would 2 semiphores to alternate between server/client access and something like a flag in the shared memory to indicate which one of the clients is the next one to play work?
    Or perhaps there is a more "proper" way to do it, relying solely on semiphores?
    Last edited by Zapeth; 01-10-2015 at 02:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple processes accessing same shared library
    By yogeeshgv in forum Linux Programming
    Replies: 1
    Last Post: 07-28-2010, 02:18 PM
  2. Trackin Memory Accesses
    By lsolano in forum Linux Programming
    Replies: 8
    Last Post: 07-28-2009, 02:15 PM
  3. Global arrays shared between multiple source files
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 08-14-2008, 06:29 PM
  4. shared libraries, datasegment and multiple processes
    By ashim_k1 in forum Linux Programming
    Replies: 1
    Last Post: 02-28-2008, 02:23 PM
  5. how expensive are memory, L1, L2 accesses?
    By cyberfish in forum C++ Programming
    Replies: 12
    Last Post: 08-20-2007, 07:53 PM

Tags for this Thread