CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
The Pipeline thread model is based on a series of tasks, each of which depends on the previous task. Have a look at Figure 5 which illustrates the situation:
Figure
5
In the figure above, the main thread creates a series of threads, each of which will wait until the previous thread is finished executing. This kind of threading relationship is good if your task has certain stages and each of these stages is dependent on another. For example, your task could be processing input data and the process could have a few sub-tasks such as:
Filter all the non-valid characters, such as <, >, !, etc.
Check if the data is formatted correctly
Format all the numbers with currency sign and decimal points
Process the input
In this kind of situation, the next task can only be started if the previous task has finished. In the previous model, this is in effect what we were doing, as the factorial field was only set at the end of the thread. However, the proper way to implement the Pipeline thread model is to explicitly test that the thread has ended.
A few changes need to be made to the Peer thread example to make it part of the Pipeline model. First, we'll show the code for frmCalculate:
Again, the changes here are small. The above method no longer has to check if factorial has been set, and is able to thus execute since it can assume the factorial has been calculated. This example could be useful when, for instance, you are waiting on a DataSet to fill, before performing some further calculations. This would enable the thread to fire as soon as the thread that fills the DataSet is complete. Of course, in a real application, error checking would have to be implemented as the thread could have completed but ended abruptly because of an error, or because of an Abort() instruction from another thread.
The traps you have to watch out for are the same traps that can occur with any thread. The first thread could be placed in an infinite loop, in which case, the second thread would never execute. By ensuring this can never happen in your first thread, you ensure that the second thread will execute and complete. In addition, you have to watch out for the thread ending unpredictably, due to an error or otherwise, as mentioned in the previous paragraph.
This concludes the discussion of the three models that can be applied to threading. By modeling your application to one of these, you should become familiar with the structure of the code you would need to use.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 1023
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved