# How to use threads in a sketch?

**URL:** <https://discourse.processing.org/t/how-to-use-threads-in-a-sketch/17832>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [February 15, 2020, 3:33am UTC](https://discourse.processing.org/t/how-to-use-threads-in-a-sketch/17832 "2020-02-15T03:33:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 15, 2020, 6:12am UTC](https://discourse.processing.org/t/how-to-use-threads-in-a-sketch/17832/2 "2020-02-15T06:12:23Z")

</div>

> [@spflanze](#):
>
> In my application the producer thread reads data from a serial bus,

Callback **serialEvent()** is already invoked by Serial’s thread:  
[Processing.org/reference/libraries/serial/serialEvent\_.html](http://Processing.org/reference/libraries/serial/serialEvent_.html)

So it can act as a “producer” thread like in this example:

> [@Using two different readStringUntil "characters"](https://discourse.processing.org/t/using-two-different-readstringuntil-characters/10769/6):
>
> The solution I gave on that link expects the Arduino C code to send the multi-data as if they were a row of tab-separated values (TSV): face_with_monocle That is, each value is followed by a \t character; except last 1, which is followed by an \n instead: nerd_face Serial.print(temperature); Serial.write('\t'); Serial.print(masse); Serial.write('\t'); Serial.print(humidite); Serial.write('\t'); Serial.print(comptage); Serial.write('\t'); Serial.println(son); // implies '\n' At the Pro…

---

_[View the full topic](https://discourse.processing.org/t/how-to-use-threads-in-a-sketch/17832)._
