Thread: using shared memory in c

  1. #1
    Registered User
    Join Date
    Apr 2002

    Question using shared memory in c


    I'm working on an assignment for a class involving using multiple threads, and creating pipes to communicate between the threads (all sorts of goodies). The professor gave us an example program from which to get ideas off of, only I'm having trouble figuring out what he did when he set up the shared memory. I really would like to do the program in c, but unless I can figure out what I'm doing, I'll have to resort to doing it in Java. Here's what the code looks like for setting up the shared memory resource:

    //first, the variables

    int smap1, i, j, k, p, sem, fd;
    pid_t pid;
    static int pp[20], ser[2];
    char c;
    caddr_t R1; //been trying to figure out what type this is

    //shared memory code

    /*Get map1 segment for shared array R1 */
    R1=mmap(o, smap1, PROT-READ|PROT_WRITE, MAP_SHARED, fd, 0);
    close (fd);

    If any is familiar with this, any help would be appreciated. Also, can anyone recommend any good books in working with multiple threads in c? I was trying to figure out the fork() function, and am having trouble with that too!
    Thanks in advance!


  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    I do not understand what you're asking.

    Perhaps take a look at this site

    Has a lot of good info on IPC, RPC, threads etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Partly shared memory
    By DrSnuggles in forum C++ Programming
    Replies: 13
    Last Post: 01-21-2009, 03:35 AM
  2. Shared Memory semaphores?
    By Ironic in forum C Programming
    Replies: 0
    Last Post: 10-31-2008, 07:13 PM
  3. Shared memory implementation using thread
    By kumars in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 04:24 AM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM
  5. Shared memory in Linux: B-TREE of structures
    By zahid in forum Linux Programming
    Replies: 3
    Last Post: 01-26-2002, 11:15 PM