void loop ()
{
while (1)
{
uint32_t now = pros::millis();
a++;
b+=a;
mutex.give();
pros::Task::delay_until(&now, 100);
}
}
void f()
{
if (joy1->get_digital(DIGITAL_A)) //if i don't pressed DIGITAL_A ,the loop() will stop?
{
mutex.take(10); // if out of time he will cout << last a?
std::cout<<a<<std::endl;
}
}
void g()
{
if (joy1->get_digital(DIGITAL_X))
{
mutex.take(10);
std::cout<<b<<std::endl;
}
}
Vision debugging is very, very cumbersome.
I plan to write a convenient debugging tool for students.
Vision is a separate thread whose loop time is controlled at 20 ms
But the lvgl thread cycle time is 100 ms.
I plan to use mutexes to solve the asynchronous problem.
But he always breaks down.I’m analyzing the reasons.
Not sure if your early school teachers did this, but imagine a classroom where you’re having a discussion. Only one student is allowed to speak at a time, and that student is determined by whomever is holding a designated ball. Students can request the ball. If they get the ball, they can give it up and let someone else take it.
You can think of a mutex operating in a similar manner. I’ll try to type up a more concrete example if you need it when I get to my computer (and not my phone).
My home computer does not have their source code. Many of them are just pseudo-codes that I temporarily simulate. My English is not very good. Sometimes I feel that the code can be expressed more clearly.
I tested it today, and I think pros or vex os seem to have finished thread safety.
If it only interacts with the main thread, Mutexes are not much needed.