shmget, can this be "segmented"

This is a discussion on shmget, can this be "segmented" within the C Programming forums, part of the General Programming Boards category; Basically, my question is, I need to have multiple clients write requests to a shared memory block and a single ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    245

    shmget, can this be "segmented"

    Basically, my question is, I need to have multiple clients write requests to a shared memory block and a single server to process these requests and return them to the right owner.

    Handling the client placing requests is easy as all clients can just use a lock to put their request in the shared memory.

    The question is, how do I allocate a segment of the shared memory to each client, so that the client can read on this segment, and wait for the "server" to place the result in that chunk?

    I haven't seen anyway to segment shared memory like this.. perhaps if someone knows some standard functions to point me in the right direction?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,680
    Instead of trying to manage multiple shared blocks (at the OS level), create a single shared block that's able to accommodate up to N simultaneous clients. When a client issues a request to the server, it's allocated a client-response handle/entry somewhere in the shared block. When the client receives the response, it can return the handle/entry back to the server for reuse, or use it again in subsequent requests.

    Or you could consider other IPC methods: sockets, pipes, message queue's

    gg

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    245
    Quote Originally Posted by Codeplug View Post
    Instead of trying to manage multiple shared blocks (at the OS level), create a single shared block that's able to accommodate up to N simultaneous clients. When a client issues a request to the server, it's allocated a client-response handle/entry somewhere in the shared block. When the client receives the response, it can return the handle/entry back to the server for reuse, or use it again in subsequent requests.

    Or you could consider other IPC methods: sockets, pipes, message queue's

    gg
    Thanks for the response.

    It's a course project, so I have to use RPC.

    I would like to use a single shared block, but I'm not sure how each client gets allocated a portion of the shared memory in which to write... ideally, if there are 4 clients, each client should be able to write to his portion of the shared memory without interference...

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,680
    >> but I'm not sure how each client gets allocated a portion of the shared memory
    Simple approach is to just use an array of per-client structures, and an index representing "the next structure to allocate to a client". And once a structure has been given to a client, it's never returned. Then to support N clients, the array would contain N elements. First client gets index 0, next client gets index 1, etc...

    If you need to support the notion re-usable client structures, then you would need to scan the array for the next available structure to assign.

    gg

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    245
    Quote Originally Posted by Codeplug View Post
    >> but I'm not sure how each client gets allocated a portion of the shared memory
    Simple approach is to just use an array of per-client structures, and an index representing "the next structure to allocate to a client". And once a structure has been given to a client, it's never returned. Then to support N clients, the array would contain N elements. First client gets index 0, next client gets index 1, etc...

    If you need to support the notion re-usable client structures, then you would need to scan the array for the next available structure to assign.

    gg
    I see. This is starting to make a lot of sense now.

    so I would need one general holder for each client to "register" himself. The server reads from this place, and then returns a pointer to some chunk of the shared memory to the new client. all interactions after that go between those new chunks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need larger shmget() size.
    By endomlic in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 02:22 PM
  2. shmget problem
    By g_p in forum C Programming
    Replies: 8
    Last Post: 12-03-2006, 07:17 AM
  3. shmget returning invalid segment size specified
    By BobS0327 in forum Linux Programming
    Replies: 6
    Last Post: 11-08-2006, 05:39 PM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 01:15 AM
  5. shmget function
    By clancyPC in forum C Programming
    Replies: 5
    Last Post: 06-19-2002, 10:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21