What happens if two or more threads trying to access static data at the same time??

10 pts.
Tags:
C++
Threads
What happens if two or more threads trying to access static data at the same time??
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

The simple answer is chaos MIGHT ensue. Consider, only one copy of the data item exists. Suppse thread1 reads to inspect the variable and update it. Before writing the new copy, thread2 has written a changed value. Worse, if the data member is an array and thread1 is sorting it while thread2 is updating part of it …
Synchronisation (thread harmonisation) constructs are essential. With regard to this, older C-style constricts such as strtok() use static fata beneath the covers and are thus not thread-safe.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: