Freezing and Thawing Threads in the Debugger

From RAD Studio
Jump to: navigation, search

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 PauseButton.png on the IDE when the application is running.
  • An exception occurs that stops the application.

To freeze a thread when using the Debugger

  1. Open the Threads window by selecting View > Debug Windows > Threads.
  2. In the Threads window, right-click the thread you want to freeze.
  3. 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

  1. Open the Thread Status window by selecting View > Debug Windows > Threads.
  2. In the Threads window, right-click the frozen thread that you want to thaw. (The Status should be Frozen.)
  3. 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).

  1. Click Start | Programs | Embarcadero RAD Studio Sydney | Samples to navigate to the \Object Pascal\RTL\Threads\thrddemo.dproj sample.
  2. In the Project Manager, open the SortThds.pas file.
  3. In the Code Editor, find (Ctrl+F) the following source line:
    Sort(Slice(FSortArray^, FSize));
  4. Click the gray gutter column to set a breakpoint (Breakpoint.png) on that code line.
  5. Press F9 or choose Run > Run to run the program.
  6. In the Thread Sorting Demo window, click Start Sorting. Processing stops at the line containing the breakpoint.
  7. Open the Thread Status window using either View > Debug Windows > Threads or Ctrl+Alt+T.
  8. Notice that the thread named TBubbleSort is in the Stopped state with the Status showing Breakpoint.
  9. Press F9 again, and notice that the TQuickSort thread was created and is in the same state as TBubbleSort.
  10. 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.


See Also