using shared memory in c

This is a discussion on using shared memory in c within the C Programming forums, part of the General Programming Boards category; Hi, I'm working on an assignment for a class involving using multiple threads, and creating pipes to communicate between the ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    7

    Question using shared memory in c

    Hi,

    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 */
    smap1=12500;
    fd=open("/dev/zero",O_RDWR);
    R1=mmap(o, smap1, PROT-READ|PROT_WRITE, MAP_SHARED, fd, 0);
    close (fd);
    R1[100]=17;

    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!

    flawildcat

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

    Perhaps take a look at this site

    http://www.cs.cf.ac.uk/Dave/C/

    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, 08:13 PM
  3. Shared memory implementation using thread
    By kumars in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 05:24 AM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 05: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

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