Cellular
lock()
The Cellular object does not have built-in thread-safety. If you want to use things like Cellular.command() from multiple threads, including from a software timer, you must lock and unlock it to prevent data from multiple thread from being interleaved or corrupted.
A call to lock lock() must be balanced with a call to unlock() and not be nested. To make sure every lock is released, it's good practice to use WITH_LOCK like this:
// EXAMPLE USAGE
void loop()
{
WITH_LOCK(Cellular) {
Cellular.command("AT\r\n");
}
}
Never use lock() or WITH_LOCK() within a SINGLE_THREADED_BLOCK() as deadlock can occur.