Question

I work on my hobby project , online checkers boards game, based on iocp multithredaed server.

Below is struct of board and viewer:

   typedef struct _board {
          ....
      PPER_viewer                Viewerlist;
          ...
    } board, *PPER_board;

  typedef struct _viewer {
     SOCKET sc;
     struct _viewer *pCtxtBack; 
     struct _viewer  *pCtxtForward;
    } viewer, *PPER_viewer;

Viewerlist in board structure is a start of doubly linked list of viewer. The list is updated with viewer structure when players sit down/up to particular board. I also use Viewerlist to send piece movement to all viewer at the table. Because of multithreading I use EnterCriticalSection on Viewerlist.

My confusion: How to deal with situation, when there are 10 opened boards on my server? It seems to be inappropriate to use the same entercriticalsection for all opened boards? For example in the case 30 opened boards Should I make 30 separated Entercriticalsection for each boards?

Thanks in advance for yours help.

Was it helpful?

Solution

You need a one to one relationship between a critical section object and the shared data. So if the boards are independent from each other, then have one critical section per board.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top