View Single Post
  #5   Spotlight this post!  
Unread 04-22-2012, 02:56 AM
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 152
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Multithreading and locking?

One example worth looking at is the PIDController. It spawns a task which updates every 50ms from the PIDInput and writes its results to PIDWrite. That will serve as a good example. But if there's a lack of clarity as to what you're really trying to do, here's "it" in a nutshell. Since you have two tasks running at the same time, one must be careful to not wind up modifying something while it is being read by the other task. The lock basically says that the other task cannot get their lock until you unlock on the other one. One must also be careful to program in a manner where you always give up a lock that you've taken - or else the other thread will be forever waiting to gain the lock which you never give up.... and similarly, if you take a lock, you have to be careful to make sure you don't accidentally call a function which tries to take the lock a 2nd time which would result in the same deadlock situation.

bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote