# It's really need cRxLock and cTxLock in Queue struct?

**URL:** <https://forums.freertos.org/t/its-really-need-crxlock-and-ctxlock-in-queue-struct/6597>\
**Category:** Kernel\
**Created:** [June 5, 2017, 11:06am UTC](https://forums.freertos.org/t/its-really-need-crxlock-and-ctxlock-in-queue-struct/6597 "2017-06-05T11:06:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 5, 2017, 11:06am UTC](https://forums.freertos.org/t/its-really-need-crxlock-and-ctxlock-in-queue-struct/6597/1 "2017-06-05T11:06:10Z")

</div>

**[ctc8631](https://sourceforge.net/u/ctc8631/)** wrote on [Monday, June 05, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/1de4c043/#652d):

Hello, I’m keep learning FreeRTOS source code,  
But in queue.c, I’m not really understand why need cRxLock and cTxLock,  
I know that in send or receive function it can lock rx and tx when it check the timeout,  
and in this situation the ISR event will record in cRxLock and cTxLock,  
after checking timeout, it will check Lock value and release lock.

But I think the check timeout is not really long, why just put check into critical section,  
then there is no need to use cRxLock and cTxLock and save release lock which is not short execute

I think maybe there is a key to design Lock, can anyone give me some hint, thanks

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [June 5, 2017, 2:34pm UTC](https://forums.freertos.org/t/its-really-need-crxlock-and-ctxlock-in-queue-struct/6597/2 "2017-06-05T14:34:08Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, June 05, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/1de4c043/#652d/b4eb):

As I recall the rx and tx locks are used to allow queues to be used from  
tasks and interrupts at the same time. If a queue is locked then an  
interrupt using the queue knows it can modify some data structures but  
not others - the structures it can’t modify are then modified from the  
task level when the queue is unlocked. So:

1. A task locks a queue and starts accessing it.
2. An interrupt uses the queue, but noticing it is locked, does not  
complete the queue operation.
3. When the task unlocks the queue it notices an interrupt also accessed  
the queue and completes the operation the interrupts started.
