Can threads communicate with each other while in multithreading?

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

1 Like

Have you looked at Channels Tasks · The Julia Language
It might be primitive you look for.

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, semaphores, locks, conditions, and channels.

Safe inter-thread communication (without deadlocks or unwanted race conditions) 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.

2 Likes