Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 9 months ago.
What's difference Thread::wait and wait funtion ?
Hello I wonder What is difference Two function and operation Thread:wait() and wait()
Is Thread::wait to effect all Task? include main function.
main
void main() { txThread.start(txTask); while (true) { //kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG); //kw40z_device.SendPressure(int_svm); blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/ wait(0.05); } }
My task
void txTask(void) { accel.accel_config(); wait(0.5); while (true) { UpdateSensorData(); Thread::wait(100); } }
1 Answer
6 years, 8 months ago.
The source code is pretty clear. Though it probably depends on which version of mbed you are using and if you have rtos enabled or not. But current version with rtos enable code is here:
https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_wait_api_rtos.cpp
The function wait(float), calls Thread::wait() itself to carry out any part of wait in the millisecond range. This way your call to wait(float) does not block the rest of the program. It uses a ticker to track the total wait time in microseconds. Once it comes back from the Thread:wait() delay (some number of milliseconds later) it waits in a loop for any remaining microseconds to expire. So if you ask for a 10500us wait, Thread::wait() will be called with 10ms, and when you come back the ticker will count down the remaining 500us so you have the correct total wait time.
In otherwords, they are very similar. Use wait(float) if you need a wait time that is not a whole number of milliseconds.