It is not easy to debug multithreading application because of threads jumping and interleaving each other. When I was debugging some algorithms, I always change the application setting to single threaded.
Things could be a lot easier. Delphi has a IsDebuggerPresent function that declares the Win32 API.
unit Windows;
..
..
function IsDebuggerPresent: boolean; external 'kernel32.dll';
It can be used to detect if IDE or debugger is present. Therefore, I could just add the following code:
{$IFDEF DEBUG}
if (IsDebuggerPresent) then ThreadNumber := 1;
{$ENDIF}
The above code allows you to force debug single-threaded application and you don’t need to change any single line of code when you want to deploy your application as multithreading. The compiler directive check {$IFDEF DEBUG} makes sure the above code only is injected to the production binaries which is RELEASE mode.
Delphi / Object Pascal
- Delphi is 30 Years Old!
- Reviews of FixInsight - Delphi Static Code Analyser
- Lighting-fast Delphi 2007 Compiling Speed
- The Inline Keyword in Delphi
- Does Parallel.For in Delphi Actually Improve the Performance?
- Delphi TParallel Cleanup Needed
- Delphi Compiles Code to Linux 64-bit Server
- Integer Performance Comparisons of Delphi Win32, Win64 and Linux64 for Single/Multithreading Counting Prime Number
- How to Check If Running in 64-bit Windows Environment using Delphi?
- How to Check Debugger Present in Delphi?
- Delphi Static Code Analyser - FixInsight
- Optimal SizeOf Code Generated in Delphi 2007
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: SQL Exercise - How to Swap Columns? (MySQL)
Next Post: LOGO Turtle Tutorial How to Draw Fractal Stars?