Original Post
I have a question regarding what the problem with multithreading is, and more specifically, what the problem with sharing data between threads is.
Is the problem that two threads might access the same data simultaneously, causing a problem? I don''t see how this is even possible on a single processor system, since the processor can really only execute one instruction at a time.
Or...
Is the problem that, for example, you might delete the last element of a linked list in one thread, and before you can set the previous element''s next pointer to NULL, another thread tries to do a theNode->next, which works fine, since the next pointer hasn''t been set to NULL, but gives you undefined behavior since the node has really been deleted?
The reason I''m asking is because I want to know if it''s ok to share simple data between threads, such as a global boolean value to tell a thread whether or not it should continue running. In this case of using a global boolean, on a single processor that data will never be able to be accessed simultaneously (at least that''s what I''m thinking), so there should be no problem with data sharing in this case, right?
And how about on a multi-processor system? Is sharing simple data such as a global boolean ok? I would think that it might be possible for the two processors to attempt to access the same data simultaneously in this situation and cause a problem.
Thanks for your help.
Russell