# Color threadsafe in Processing?

**URL:** <https://discourse.processing.org/t/color-threadsafe-in-processing/4563>\
**Category:** Coding Questions\
**Created:** [October 17, 2018, 3:38pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563 "2018-10-17T15:38:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 17, 2018, 3:38pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/1 "2018-10-17T15:38:02Z")

</div>

I have two threads running in one sketch and have the problem that the colors interfere and flicker. the background color changes by setFill of a pShape in one thread. I suppose that there is no “clean” solution because color in Proc is not threadsafe and I will have to find a workaround like setting background multiple times during draw()?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [October 17, 2018, 11:05pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/2 "2018-10-17T23:05:51Z")

</div>

UI libraries in general are not thread-safe. Every UI library I know of uses a single thread to draw to the screen, otherwise you get problems like the ones you’re describing.

What are you trying to do with multiple threads drawing to the screen?

---

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 19, 2018, 6:29am UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/3 "2018-10-19T06:29:34Z")

</div>

Thanks Kevin. I need muiltiple Monitors with different views.

---

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 19, 2018, 7:20am UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/4 "2018-10-19T07:20:44Z")

</div>

Or is there a possibility to extract a (Full HD) part from a 4K Monitor draw() picture to show only this by beamer and having at the same time the full view on the monitor?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [October 19, 2018, 9:08am UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/5 "2018-10-19T09:08:32Z")

</div>

> [@gerome](#):
>
> I need muiltiple Monitors with different views.

Color is far from the only issue you’ll run into a some point doing this. _Lots of things_ are not threadsafe. A few things in the OpenGL renderers don’t even play nice in the same VM.

> [@gerome](#):
>
> Or is there a possibility to extract a (Full HD) part from a 4K Monitor draw() picture to show only this by beamer and having at the same time the full view on the monitor?

What OS? You’re really looking at an OS-specific mirroring option. Or other than that an external splitter, although they’re somewhat expensive - good if you want to drive more than one projector from the same display though.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [October 19, 2018, 9:07pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/6 "2018-10-19T21:07:46Z")

</div>

> [@gerome](#):
>
> Or is there a possibility to extract a (Full HD) part from a 4K Monitor draw() picture to show only this by beamer and having at the same time the full view on the monitor?

If I were you, I’d probably consider using Processing as a Java library, which would allow you to have multiple windows displaying and communicating with each other.

Shameless self-promotion: here is a tutorial on using Processing as a Java library:

> **[Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)**
>
> Learn how to use Processing as a Java library.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [October 19, 2018, 10:07pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/7 "2018-10-19T22:07:11Z")

</div>

> [@Kevin](#):
>
> If I were you, I’d probably consider using Processing as a Java library, which would allow you to have multiple windows displaying and communicating with each other.

This unfortunately isn’t by itself a panacea for this, and depending on the renderer (particularly OpenGL) has a tendency to crash. The only safe way is splitting the actual single output or running in separate processes.

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [October 19, 2018, 10:16pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/8 "2018-10-19T22:16:48Z")

</div>

Hmm I’ll take your word for it, but I’d still consider it worth trying out.

---

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 20, 2018, 11:59am UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/9 "2018-10-20T11:59:33Z")

</div>

Thanks. splitting could in this case possibly the simplest solution. And i have some time pressure. Win7 64bit

---

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 20, 2018, 12:07pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/10 "2018-10-20T12:07:13Z")

</div>

Thanks vor the Tutorial Link. I would have done this before if i Had a good solution For the communication between max cycling74 and processing via osc. I would appreciate a tutorial forum this topic.

---

<div class="post-metadata">

**Author:** ![gerome](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerome](https://discourse.processing.org/u/gerome)\
**Post date:** [October 22, 2018, 12:30pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/11 "2018-10-22T12:30:11Z")

</div>

Has anybody a recommendation for splitting on Win7 64bit  
a 3840 x 2160 picture to two monitors: one 4K and one FullHD. or  
a 1920 x 2160 picture to two FullHD monitors for ?

I mean how to route one section of draw() output to one monitor and another section to another?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 24, 2018, 5:15pm UTC](https://discourse.processing.org/t/color-threadsafe-in-processing/4563/12 "2018-10-24T17:15:49Z")

</div>

> [@gerome](#):
>
> I mean how to route one section of draw() output to one monitor and another section to another?

And, just to re-confirm, you can’t map your OS to display fullscreen across the two monitors, then run the Processing sketch fullscreen? This is the solution I am used to – that monitor-mapping is an OS-level issue, or that you use a dedicated hardware splitter and plug a single computer graphics out into it.
