concurrency?

This is a discussion on concurrency? within the C Programming forums, part of the General Programming Boards category; Hi?does anyone know anything about Distributed Systems e.g, Protocol Entity (PE), processes, synchronization, token passing or message passing using asynchronous ...

  1. #1
    unregistered
    Guest

    concurrency?

    Hi?does anyone know anything about Distributed Systems e.g, Protocol Entity (PE), processes, synchronization, token passing or message passing using asynchronous messaging...or Concurrent programming..

    I have a project on concurrent programming using locks , unlocks for a distributed service...

    i need some help and a few tips on how to tackle this problem..

    cheers..
    Atif

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    18
    HACKERS MANIFESTO (NOTE MOST WAS CUT OFF) (PEOPLE SAID IT WAS TOO LONG)
    This is our world now... the world of the electron and the switch, the beauty of the baud.
    We make use of a service already existing withoutpaying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals.
    We explore... and you call us criminals.
    We seek after knowledge... and you call us criminals.
    We exist without skin color, without nationality, without religious bias... and you call us criminals.
    You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals.

    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

    I am a hacker, and this is my manifesto. You may stop this individual,but you can't stop us all... after all, we're all alike.
    +++The Mentor+++

  3. #3
    Unregistered
    Guest

    concurrency

    Hi Tyrael, i could not find anything from the sites that you gave me..

    maybe if i gave you some of the notes from my project, that way may be you will know which bits of information i require, if thats ok with you..

    Basically, the program is to be divided conceptually into application and the Protocol Entity (PE).

    The Task of the PE is to provide a simple locking service invocked by the application side.

    The locking mechanism is based on token passing, i.e. all participating PE's form a logical ring, sending/receiving messages to/from just one other PE in such a way that a message from any one PE can reach any other PE; being forwarded as necessary by any intervening PE's.

    A distinguished message represents the token, and the PE at present holding the token, and only that PE, can grant the lock to its application.

    To prevent the token from "buzzing" and thereby consuming communications capacity, it will be held at some PE if there are no outstanding lock requests. A PE requested for the lock may send a demand message around the ring to notify the token holding PE that the token is required.

    The PE's observe the following rules:


    1. on lock request: if holding token unset holding token; grant lock

    2. on unlock: unset demand flag; forward token

    3. on lock needed: circulate demand if demand flag is unset

    4. on receiving demand message: set demand flag; forward token if holding token

    5. on receiving token: if waiting for lock then grant lock;
    if demand flag set then unset demand flag; forward token {else hold token}

    demand flag, holding token, etc. are boolean local variables for each participating PE.

    Atif.

  4. #4
    Unregistered
    Guest
    hi?

    well i spoke to my tutor about the Application part and he told me that the application is implemented under the main method by making a procedure call to the PE, if you know what i mean. , and then the PE is generated by using the fork() process.

    Basically the application part is called the Testing between the PE.
    The Testing (App) sends an application_demand to the PE via message queues, which is known as a way of communicating between processes.

    And the token is communicated between the PE to PE by using the message queues.

    So, i did some research and found something on message queues, all i need help with is the implementation of the application to the PE, if someone is willing to help that would be great because i only have a few days left before the due date..

    here is the code for message queues..all that is needed for my project is the sending/recieving of messages, so discard the other functions in this program.

    kind regards
    Atif

    **********************************************
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/msg.h>

    #define MAX_SEND_SIZE 80

    struct mymsgbuf {
    long mtype;
    char mtext[MAX_SEND_SIZE];
    };

    void send_message(int qid, struct mymsgbuf *qbuf, long type, char
    *text);
    void read_message(int qid, struct mymsgbuf *qbuf, long type);
    void remove_queue(int qid);
    void change_queue_mode(int qid, char *mode);
    void usage(void);


    int main(int argc, char *argv[])
    {
    key_t key;
    int msgqueue_id;
    struct mymsgbuf qbuf;

    if(argc == 1)
    usage();

    /* Create unique key via call to ftok() */
    key = ftok(".", 'm');

    /* Open the queue - create if necessary */
    if((msgqueue_id = msgget(key, IPC_CREAT|0660)) == -1) {
    perror("msgget");
    exit(1);
    }

    switch(tolower(argv[1][0]))
    {
    case 's': send_message(msgqueue_id, (struct mymsgbuf
    *)&qbuf,
    atol(argv[2]), argv[3]);
    break;
    case 'r': read_message(msgqueue_id, &qbuf,
    atol(argv[2]));
    break;
    case 'd': remove_queue(msgqueue_id);
    break;
    case 'm': change_queue_mode(msgqueue_id, argv[2]);
    break;

    default: usage();

    }

    return(0);
    }

    void send_message(int qid, struct mymsgbuf *qbuf, long type, char
    *text)
    {
    /* Send a message to the queue */
    printf("Sending a message ...\n");
    qbuf->mtype = type;
    strcpy(qbuf->mtext, text);

    if((msgsnd(qid, (struct msgbuf *)qbuf,
    strlen(qbuf->mtext)+1, 0)) ==-1)
    {
    perror("msgsnd");
    exit(1);
    }
    }

    void read_message(int qid, struct mymsgbuf *qbuf, long type)
    {
    /* Read a message from the queue */
    printf("Reading a message ...\n");
    qbuf->mtype = type;
    msgrcv(qid, (struct msgbuf *)qbuf, MAX_SEND_SIZE, type, 0);

    printf("Type: %ld Text: %s\n", qbuf->mtype, qbuf->mtext);
    }

    void remove_queue(int qid)
    {
    /* Remove the queue */
    msgctl(qid, IPC_RMID, 0);
    }

    void change_queue_mode(int qid, char *mode)
    {
    struct msqid_ds myqueue_ds;

    /* Get current info */
    msgctl(qid, IPC_STAT, &myqueue_ds);

    /* Convert and load the mode */
    sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode);

    /* Update the mode */
    msgctl(qid, IPC_SET, &myqueue_ds);
    }

    void usage(void)
    {
    fprintf(stderr, "msgtool - A utility for tinkering with msg
    queues\n");
    fprintf(stderr, "\nUSAGE: msgtool (s)end <type>
    <messagetext>\n");
    fprintf(stderr, " (r)ecv <type>\n");
    fprintf(stderr, " (d)elete\n");
    fprintf(stderr, " (m)ode <octal mode>\n");
    exit(1);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 33
    Last Post: 05-14-2009, 10:15 AM
  2. Unsure on how to approach this concurrency problem
    By osiris^ in forum C# Programming
    Replies: 3
    Last Post: 04-29-2008, 11:47 PM
  3. Maximum concurrency
    By CornedBee in forum Linux Programming
    Replies: 15
    Last Post: 11-23-2007, 05:55 AM
  4. waitable boolean class (concurrency)
    By underthesun in forum C++ Programming
    Replies: 11
    Last Post: 11-12-2007, 10:36 AM
  5. Concurrency documentation
    By subdene in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 02-16-2005, 10:14 AM

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