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 / 435
434  |  436
Subject: 
Re: RCX Programming Questions and Sensor Ideas
Newsgroups: 
lugnet.robotics
Date: 
Wed, 11 Nov 1998 01:06:38 GMT
Original-From: 
Paul Haas <paulh@hamjudo#nomorespam#.com>
Viewed: 
2914 times
  
On Tue, 10 Nov 1998, Joshua Delahunty wrote:

An example.  Say you want to prevent two tasks from fighting over motor
1.  Just insert an instruction in each task before operating the motor
to check that var 31 contains zero.  If it does, set var 31 to 1 and
control the motor, then set var 31 to 0 again.  If a task sees var 31 is
non-zero then you can program it to wait or abort as you wish.

Kekoa Proudfoot wrote:
This assumes that the check and the set are, together, atomic.  Does the
SDK document describe what if/why this might be atomic?  I haven't had a
chance to read it in enough detail to find this answer for myself.

*I* can read it, though <g>, and I can find nothing that indicates a
"safe" way to implement semaphores.

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 that technique a few weeks ago.  Email me if you want it.

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.

I was lazy and wasted the variable "done".  It isn't really needed.

--
paulh@hamjudo.com  http://www.hamjudo.com
The April 97 WebSight magazine describes me as "(presumably) normal".



Message has 1 Reply:
  Re: RCX Programming Questions and Sensor Ideas
 
(...) 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. (26 years ago, 11-Nov-98, to lugnet.robotics)

Message is in Reply To:
  Re: RCX Programming Questions and Sensor Ideas
 
(...) ...and it would be my sincerest recommendation that you NOT read it, Kekoa. It would be safer from the reverse-engineering standpoint that you NOT use this SDK in any manner. *I* can read it, though <g>, and I can find nothing that indicates a (...) (26 years ago, 10-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
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
1 hour ago
Custom Search

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