Need help with semaphore creation/syncronization strategy.

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Need help with semaphore creation/syncronization strategy.

    I've been playing with System V IPC semaphores a bit, and I've come to a
    point where I'm stuck.

    I've got two processes (call them master and slave) which share a
    semaphore. I'm using the race condition avoidance algorithm Stevens
    describes in UNP Volume 2. The master creates a semaphore, initializes
    it to zero (i.e. claims the lock), then does a semop() to force
    sem_otime to go non-zero. The slave loops waiting for sem_otime.

    The problem is, I don't know how to handle the case where a previous
    master process may have died unexpectedly and left an orphaned semaphore
    in the kernel. How would the slave recognize this condition? As far as
    the slave can tell, the semaphore is initialized, so it assumes the
    master is ready to go.
    Roy Smith Guest

  2. Similar Questions and Discussions

    1. Process syncronization in perl?
      I need to manage inter-process syncronization in perl. I'm running a multi-platform software build on 4 machines, all sharing a common NFS mounted...
    2. ANNOUNCE: POSIX::RT::Semaphore 0.01
      POSIX::RT::Semaphore is a Perl interface to POSIX.1b (Realtime) semaphores, at least as supported by your system. ;-) RT semaphores are objects...
    3. Syncronization
      Hello, Does anyone know how to syncronize a movieclip in two different flash movies. So that when you move from the first instance of the...
    4. semaphore example needed
      Hi all, I tried to use IPC::Semaphore but tried for a long time without success. What I want to do is like this : I want to limit a perl...
    5. Semaphore tutorial?
      Does anybody have a good tutorial for how SysV semaphores work, specifically the semop() function? I've read the description in Stevens' Unix...
  3. #2

    Default Re: Need help with semaphore creation/syncronization strategy.


    okay, here's one way i thought of, i'm a bit of a newbie on semaphores
    and i''ve only had experience with pthreads on solaris so if it's
    stupid: i'm sorry

    okay, i'd put a piece of code like this to figure out if the
    server fails:
    i used 2000 but, you may want a bigger number, the assumption is that
    the server wont run 2000 times in one itteration of the client but, i
    think i'm right with this code, if i'm wrong and you do get it please
    post it, i like thread coding :)


    int i = 2000;

    //i used this to as an example if you wanna keep the thing
    //running indefinitley
    while(true)
    {
    if(sem_getvalue(&your_semaphore) == 0)
    {
    --i;
    }
    else
    {
    i = 2000;
    sem_wait(&your_semaphore);
    //your critical section
    sem_post(&your_semaphore);
    }

    if (i < 1)
    {
    //server failed
    }

    }//end of while loop

    --
    Posted via [url]http://dbforums.com[/url]
    another2 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139