Open main menu

CDOT Wiki β

Changes

GPU621/Group 2

3,195 bytes added, 15:46, 16 March 2023
Freezing/Thawing Threads
=== Freezing/Thawing Threads ===
 
Freezing a thread pauses the execution of the code for that thread until the thread is thawed. Thawing allows the thread to resume normal execution after it has been frozen.
 
 
[[File:ThreadsWindowFreeze1.png]]
 
To freeze a thread, select and right-click the thread that you want frozen. In the menu that pops up, select the “Freeze” option.
 
[[File:ThreadsWindowFreeze2.png]]
 
Once you’ve selected “Freeze”, a blue pause icon will be displayed in the second column of the row of the frozen thread in the thread window. This icon indicates that the thread is currently frozen.
 
[[File:ThreadsWindowFreeze3.png]]
 
The process of thawing a thread is virtually identical. Select and right-click the frozen thread you wish to thaw, and in the menu that appears, select “Thaw” (note that the “Freeze” option is now grayed out, as the thread is already frozen).
 
 
==== Walkthrough ====
 
This is a short walkthrough that will display the effects of freezing/thawing threads during execution time of a program. The walkthrough will begin with the program already running, and paused at a breakpoint right before the program’s threads would act upon the code. The first thread of the program is currently frozen.
 
[[File:ThreadsWindowFreeze4.png|850px]]
 
In the second column of the thread window, you can see a slight variation of the active thread arrow appears when the program runs over thread 1. The arrow now has a small pause icon over it, to indicate that the current thread is frozen and will not act. While execution is paused, you can also see the values of the local variables, which may be helpful for debugging your program.
 
[[File:ThreadsWindowFreeze5.png|850px]]
 
In the coding window, you can also see a unique variation of the code execution arrow that runs down the lines of code. This is also to indicate that the line of code currently being pointed to will not be acted on by the current thread.
 
[[File:ThreadsWindowFreeze6.png|850px]]
 
Now that we know that the thread is frozen and how Visual Studio informs you about it, we can click “Continue” at the top of the window to have the program run through all of the unfrozen threads. As OpenMP does not allow for a parallel code block to finish until each thread has reached the end, we will not need to worry about the program closing prematurely.
 
[[File:ThreadsWindowFreeze7.png|850px]]
 
It can now be seen that all the other threads have completed execution, since their task of outputting their thread number has finished (as can be seen in the output window). However, the execution of the program has not yet been completed because it is still waiting for the frozen thread to complete the execution of its instructions, which it has as of yet not been able to do.
 
[[File:ThreadsWindowFreeze8.png|850px]]
 
In order to allow the frozen thread’s execution to complete, the program’s execution must first be paused. Click on the pause icon at the top of the VS window (near the "Continue" option, which is currently grayed out as there are no lines of code it can move to).
 
[[File:ThreadsWindowFreeze9.png|850px]]
 
Then, right click the frozen thread, and click the “Thaw” option to thaw the frozen thread.
 
[[File:ThreadsWindowFreeze10.png|850px]]
 
After the thread has been thawed, click the "Continue" button to resume normal execution of the program.
 
[[File:ThreadsWindowFreeze11.png|850px]]
 
From the output window, you can now see that the frozen thread, with the thread number of 1, is the one that has executed last, since it's execution was frozen until all the other threads' executions were completed.
=== Flagging Threads ===