# passing strings between tasks

**URL:** <https://forums.freertos.org/t/passing-strings-between-tasks/804>\
**Category:** Kernel\
**Created:** [December 10, 2008, 1:27am UTC](https://forums.freertos.org/t/passing-strings-between-tasks/804 "2008-12-10T01:27:45Z")\
**Posts on this page:** 4\
**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:** [December 10, 2008, 1:27am UTC](https://forums.freertos.org/t/passing-strings-between-tasks/804/1 "2008-12-10T01:27:45Z")

</div>

**[daverm](https://sourceforge.net/u/daverm/)** wrote on [Wednesday, December 10, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/2086c2df/#5f08):

What’s the best way to pass strings between tasks?  
1. xQueueCreate( maxstringlength, sizeof( char ) );  
2. xQueueCreate( 1, maxstringlength ); //inefficient because it copies MAX string length instead of actual string length  
3. xQueueCreate( 1, sizeof( char\* ) ); //also requires semaphores  
4. semaphores around a global string?

Thx,  
Dave

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 10, 2008, 2:12am UTC](https://forums.freertos.org/t/passing-strings-between-tasks/804/2 "2008-12-10T02:12:57Z")

</div>

**[spacewrench](https://sourceforge.net/u/spacewrench/)** wrote on [Wednesday, December 10, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/2086c2df/#5f08/185b):

Depends whether the receiving task needs to modify the string, and whether the sending task needs its own copy, or needs to release the memory or whatever.&nbsp; For strings that are const after sending (no task needs to modify or delete them), I’d go with 3.&nbsp; If you’re really trying to pass a buffer of data from a producer to a consumer (for example), and have the producer generate more data after the consumer is finished, then I’d go with 4: semaphores around a global buffer.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 10, 2008, 3:57pm UTC](https://forums.freertos.org/t/passing-strings-between-tasks/804/3 "2008-12-10T15:57:48Z")

</div>

**[daverm](https://sourceforge.net/u/daverm/)** wrote on [Wednesday, December 10, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/2086c2df/#5f08/6cd6):

Thx Dave.  
4 it is.  
The producer is generating variable sized non-const ‘debug’ strings that are output to a port by the consumer.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 10, 2008, 4:27pm UTC](https://forums.freertos.org/t/passing-strings-between-tasks/804/4 "2008-12-10T16:27:23Z")

</div>

**[spacewrench](https://sourceforge.net/u/spacewrench/)** wrote on [Wednesday, December 10, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/2086c2df/#5f08/3079):

Oh yeah, totally.&nbsp; That’s a great way to handle debugging output (everything spews into a common circular buffer, and some low-priority task prints it out when it has a chance).&nbsp; It can get pretty complex if you’re doing timestamping and making sure messages interleave on a line-by-line basis, plus the buffer has to be pretty big if you have a lot of high-priority output, but a robust debug/error reporting scheme makes development MUCH easier.
