To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 445
444  |  446
Subject: 
Re: RCX Programming Questions and Sensor Ideas
Newsgroups: 
lugnet.robotics
Date: 
Wed, 11 Nov 1998 10:02:47 GMT
Original-From: 
Ben Laurie <ben@algroup/spamless/.co.uk>
Viewed: 
2916 times
  
Paul Haas wrote:
2. You can use a counter, because += 1 and -= 1 are atomic operations.

    int r31;
    int done;
    r31 = 0;

    // stuff happens.
    // Heres our semaphore stuff.
    done = 0;  // We're not done yet.

    while ( ! done ) {
         while ( r31 != 0 ) {
         } ; // busy wait.
        r31 += 1;  // This operation is atomic.
        if ( r31 == 1 ) {  // Were we the only process to touch the counter?
             // Do critical section stuff here.
             done = 1;
        }
        r31 -= 1;  // Remove our reservation.
   }

Note, this isn't fair, fifo, lifo, or any other of those spiffy
attributes.  You can use this sort of semaphore to wrap around the fancy
stuff.

It isn't guaranteed to work, either, though it is likely to in the end.
This is because two processes can conspire to always have r31 == 2 when
you test for r31 == 1.

Cheers,

Ben.

--
Ben Laurie            |Phone: +44 (181) 735 0686| Apache Group member
Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org/
and Technical Director|Email: ben@algroup.co.uk |
A.L. Digital Ltd,     |Apache-SSL author     http://www.apache-ssl.org/
London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache/



Message has 1 Reply:
  Re: RCX Programming Questions and Sensor Ideas
 
(...) Oops. I don't know how the scheduler in the RCX works. It might execute 1 opcode from each task in order. If 2 tasks get in sync, then they will never leave the semaphore code as written. Here's a fixed version. I added a random backoff. (...) (...) (26 years ago, 11-Nov-98, to lugnet.robotics)

Message is in Reply To:
  Re: RCX Programming Questions and Sensor Ideas
 
(...) Check and set do not have to be atomic, they have to be ordered. The sequence is: Check all flags, when clear, set our flag, check all flags again, if only ours is set, do stuff. 1. You can dedicate a task to managing semaphores. I described (...) (26 years ago, 11-Nov-98, to lugnet.robotics)

17 Messages in This Thread:






Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR