Freezing and Thawing Threads in the Debugger
Go Up to How To Use the Debugger
Your threaded application needs to be stopped in the Debugger before you can freeze and thaw individual threads. You can stop the application in a number of ways, including the following:
- Set breakpoints and then choose Run > Run or Run > Step Over.
- Press the Pause button on the IDE when the application is running.
- An exception occurs that stops the application.
Contents
To freeze a thread when using the Debugger
- Open the Threads window by selecting View > Debug Windows > Threads.
- In the Threads window, right-click the thread you want to freeze.
- From the context menu, select the command that applies to your situation:
- Freeze - freezes the selected thread
- Freeze all other threads - freezes all the other threads, but not the selected thread
To thaw a thread when using the Debugger
- Open the Thread Status window by selecting View > Debug Windows > Threads.
- In the Threads window, right-click the frozen thread that you want to thaw. (The Status should be Frozen.)
- From the context menu, select the command that applies to your situation:
- Thaw - thaws the selected thread
- Thaw all threads - thaws all the threads, including the selected thread
To freeze and thaw threads using the THRDDEMO Sample Project
The thrddemo project contains three named threads (TBubbleSort, TQuickSort, and TSelectionSort).
- Click Start | Programs | Embarcadero RAD Studio Rio | Samples to navigate to the
\Object Pascal\RTL\Threads\thrddemo.dproj
sample. - In the Project Manager, open the SortThds.pas file.
- In the Code Editor, find (
Ctrl+F
) the following source line:Sort(Slice(FSortArray^, FSize));
- Click the gray gutter column to set a breakpoint () on that code line.
- Press
F9
or choose Run > Run to run the program. - In the Thread Sorting Demo window, click Start Sorting. Processing stops at the line containing the breakpoint.
- Open the Thread Status window using either View > Debug Windows > Threads or
Ctrl+Alt+T
. - Notice that the thread named TBubbleSort is in the Stopped state with the Status showing Breakpoint.
- Press
F9
again, and notice that the TQuickSort thread was created and is in the same state as TBubbleSort. - Press
F9
again, and notice that now the TSelectionSort thread was created and is in the same state as the other two threads.
You can now freeze any of the threads and run the other threads to demonstrate freezing. After a thread is frozen, you can then thaw the thread.