# Does TRY\_LOCK support Serial1? Build errors!

**URL:** <https://community.particle.io/t/does-try-lock-support-serial1-build-errors/34097>\
**Category:** Firmware\
**Created:** [June 26, 2017, 8:30pm UTC](https://community.particle.io/t/does-try-lock-support-serial1-build-errors/34097 "2017-06-26T20:30:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dheerajdake](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@dheerajdake](https://community.particle.io/u/dheerajdake)\
**Post date:** [June 26, 2017, 8:30pm UTC](https://community.particle.io/t/does-try-lock-support-serial1-build-errors/34097/1 "2017-06-26T20:30:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [June 27, 2017, 8:39am UTC](https://community.particle.io/t/does-try-lock-support-serial1-build-errors/34097/2 "2017-06-27T08:39:43Z")

</div>

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

> [@](#):
>
> At present there is only one shared resource that is used by the system and the application - **Serial**. The system makes use of **Serial** during listening mode. If the application also makes use of serial during listening mode, then it should be locked before use.

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

---

<div class="post-metadata">

**Author:** ![dheerajdake](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@dheerajdake](https://community.particle.io/u/dheerajdake)\
**Post date:** [June 27, 2017, 5:11pm UTC](https://community.particle.io/t/does-try-lock-support-serial1-build-errors/34097/3 "2017-06-27T17:11:29Z")

</div>

Thank you 🙂
