Question

  Asked: Jun 6 2008   1:08 PM GMT
  Asked by: Arun 18


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


C++, Threads

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

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



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.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development.

Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register