Skip to content
Advertisement

Is there a way to have threads communicate with each other?

Hi I am trying to make it so 2 threads will change the other one but I can’t figure it out this is an example of what I have

JavaScript

When they run thing2 will print 0, not the seconds. I have it so they run later this is just all the code that’s necessary

Advertisement

Answer

You need to use a semaphore so that each thread is not accessing the variable at the same time. However, any two threads can access the same variable s using global.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement