Does TRY_LOCK support Serial1? Build errors!

Hello,
I am getting build errors when using TRY_LOCK(Serial1){}. My code builds fine when I change Serial1 to Serial. Is there support for Serial1?

I have a 2 threads and both use Serial1. I have to disable access to the second thread when the first thread uses Serial1. I am using TRY_LOCK(Serial1){} for this purpose. I get the following build error

In instantiation of ‘std::unique_lock<_Mutex>::unique_lock(std::unique_lock<_Mutex>::mutex_type&, std::try_to_lock_t) [with _Mutex = USARTSerial; std::unique_lock<_Mutex>::mutex_type = USARTSerial]’:
communication_api.cpp:78:2: required from here
/usr/local/gcc-arm-embedded/arm-none-eabi/include/c++/4.8.4/mutex:452:55: error: ‘std::unique_lock::mutex_type’ has no member named ‘try_lock’
: _M_device(&__m), _M_owns(_M_device->try_lock())

/usr/local/gcc-arm-embedded/arm-none-eabi/include/c++/4.8.4/mutex: In instantiation of ‘void std::unique_lock<_Mutex>::unlock() [with _Mutex = USARTSerial]’:
/usr/local/gcc-arm-embedded/arm-none-eabi/include/c++/4.8.4/mutex:476:11: required from 'std::unique_lock<_Mutex>::~unique_lock() [with _Mutex = USARTSerial]'
communication_api.cpp:78:2: required from here
/usr/local/gcc-arm-embedded/arm-none-eabi/include/c++/4.8.4/mutex:567:6: error: ‘std::unique_lock::mutex_type’ has no member named ‘unlock’
_M_device->unlock();

Thanks
Dheeraj

As far as the docs are concerned, that’s not supported
https://docs.particle.io/reference/firmware/photon/#synchronizing-access-to-shared-system-resources

As this fearture is currently mainly meant for synchronisation between system and application threads and not between multiple application threads.

1 Like

Thank you :slight_smile: