View Single Post
  #1   Spotlight this post!  
Unread 11-02-2010, 15:55
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Task Creation and Semaphore Tutorial

Unless you have fancy code, you should not encounter this (for the most part), but watch out for race conditions and locking.
if I have task A and it is running:
Code:
CRITICAL_REGION(Sem1)
Wait(5.0);//demo purposes
CRITICAL_REGION(Sem2)
/*Code here*/
END_REGION
END_REGION
and you have Task B running:
Code:
CRITICAL_REGION(Sem2)
Wait(5.0);//demo purposes
CRITICAL_REGION(Sem1)
/*Code here*/
END_REGION
END_REGION
Assuming they were started within 5 seconds of each other, they will both lock, and nothing will happen. Why?
Task A locks Sem1 and waits for 5 seconds, where Task B starts, and Locks Sem2
Task A has waited 5 seconds, and tries to lock Sem2, but Task B has it, so It waits for B to release it.
Meanwhile, B has waited its 5 seconds, and tries to Lock Sem1, but Task A has it so it waits for A to release it.
they are each waiting for the other to do something, so they do nothing
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote