# Can threads communicate with each other while in multithreading?

**URL:** <https://discourse.julialang.org/t/can-threads-communicate-with-each-other-while-in-multithreading/91550>\
**Category:** Performance\
**Tags:** question, performance, parallel, multithreading\
**Created:** [December 12, 2022, 10:09am UTC](https://discourse.julialang.org/t/can-threads-communicate-with-each-other-while-in-multithreading/91550 "2022-12-12T10:09:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![le\_ackerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/le_ackerman/32/38731_2.png) [@le\_ackerman](https://discourse.julialang.org/u/le_ackerman)\
**Post date:** [December 12, 2022, 10:09am UTC](https://discourse.julialang.org/t/can-threads-communicate-with-each-other-while-in-multithreading/91550/1 "2022-12-12T10:09:48Z")

</div>

Hi!  
I am a beginner in parallel computing and been fooling around with different packages in multithreading.

My question is very specific:  
I want to write a code to do multithreading… and i want to know is there any way that two or more threads can communicate with each other while in multithreading…  
can i call a result from another thread (or wait for it if it has not calculated) to a different thread provided both or more are working on same?

This might sound foolish as if a thread is waiting for a result from another thread it is same as single threading but what if there are certain instances where the result from another thread is required as that task is performed on say i\_th thread…?

Can it give performance improvents…?

Any thoughts are helpful…  
And please let me know where I am thinking wrong  
Thanks

---

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [December 12, 2022, 12:32pm UTC](https://discourse.julialang.org/t/can-threads-communicate-with-each-other-while-in-multithreading/91550/2 "2022-12-12T12:32:27Z")

</div>

Have you looked at Channels [Tasks · The Julia Language](https://docs.julialang.org/en/v1/base/parallel/#Channels)  
It might be primitive you look for.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 12, 2022, 1:07pm UTC](https://discourse.julialang.org/t/can-threads-communicate-with-each-other-while-in-multithreading/91550/3 "2022-12-12T13:07:28Z")

</div>

> [@le\_ackerman](#):
>
> and i want to know is there any way that two or more threads can communicate with each other while in multithreading…

There are lots of tools for threads to communicate safely. Roughly in order of low-level to high-level, the main ones are: [atomic operations](https://docs.julialang.org/en/v1/base/multi-threading/#Atomic-operations), [semaphores](https://docs.julialang.org/en/v1/base/parallel/#Base.Semaphore), [locks](https://docs.julialang.org/en/v1/base/parallel/#Base.ReentrantLock), [conditions](https://docs.julialang.org/en/v1/base/parallel/#Base.Threads.Condition), and [channels](https://docs.julialang.org/en/v1/base/parallel/#Channels).

Safe inter-thread communication (without [deadlocks](https://en.wikipedia.org/wiki/Deadlock) or unwanted [race conditions](https://en.wikipedia.org/wiki/Race_condition)) is a central topic of multi-threaded programming and the concepts are common to many languages. The ideas take some time to get used to, but there are lots of books and other materials about this sort of thing.
