6. Thread Synchronization

< BACK  NEXT >
[oR]

Chapter 6. Thread Synchronization

The last chapter showed how processes could create additional threads to carry out background tasks or to wait for some event to occur. However, using threads is not as simple as creating a new thread and leaving it to execute. Since all threads running in an application share the same global resources and variables, there is always the chance that two threads will attempt to access the same resource at the same time. Such simultaneous access of a global resource may cause the program to fail. Because of the way the threads are scheduled, the problems caused by simultaneous access of a global resource will not occur every time the program is run. Typically such synchronization problems occur rarely enough to make tracking them down difficult but frequently enough to be annoying for the user.

There is only one sure way to avoid synchronization problems: build inand test thread synchronization techniques whenever you create additional threads. If you have difficulties in writing synchronization code, you are better off staying with a single-threaded application. You can then use other methods, such as timers or sending messages, in place of additional threads.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net