|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Multithreading and locking?
Quote:
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
Re: Multithreading and locking?
Quote:
The AxisCamera code also has some locking that you can look at. We also wrapped it a little in our code: https://github.com/rbmj/612-code/blo...ion_thread.cpp |
|
#4
|
|||
|
|||
|
Re: Multithreading and locking?
Quote:
so for example right after your includes you would put something like this... using namespace cv; using namespace std; Now that you have that instead of doing something like std::cout << cv: oint(10,10) << std::endl;You can now do this cout << Point(10,10) << endl; Just something I thought I would share with everyone. |
|
#5
|
|||
|
|||
|
Re: Multithreading and locking?
Actually, it isn't really considered good practice to use namespaces, when you start using multiple libraries with similarly named functions, it can get hectic, and its just better to get into the habit of not using them if possible.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|