Synchronization

Earlier, when we discussed a technique for passing parameters to threads using a property, you learned that problems can occur, mainly due to uncertainty about how threads are executed. You can never guarantee the order in which threads are run (unless they all have different priorities), so if one thread sets some shared data to a value that is read by another, the reading thread might run before the writing thread has actually written the data. In situations in which the running order matters, threads must be carefully synchronized.

As a simple example, consider the Stock and StockController classes shown in the StockControl.jsl file in the StockControl project. The Stock class models stock items held in a fictitious warehouse. ...

Get Microsoft® Visual J#™ .NET (Core Reference) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.