I have an application written in C++ and MFC which is multithreaded running on windows. Occasionally I do get some complaints such as deadlocks or an unhandled exception which is caused because of these threads. Normally I use visual studio (if the problem is reproducible) or else use the WinDbg to analyse the dump files generated. Is there any better way of doing this? Can  I use some other tools to do this?
122116
We have a codebase that is several years old, and all the original developers are long gone.  It uses many, many threads, but with no apparent design or common architectural principles.  Every developer had his own style of multithreaded programming, so some threads communicate with one another using queues, some lock data with mutexes, some lock with semaphores, some use operating-system IPC mechanisms for intra-process communications.  There is no design documentation, and comments are sparse.  It's a mess, and it seems that whenever we try to refactor the code or add new functionality, we introduce deadlocks or other problems.  So, does anyone know of any tools or techniques that would help to analyze and document all the interactions between threads?  FWIW, the codebase is C++ on Linux, but I'd be interested to hear about tools for other environments.    Update  I appreciate the responses received so far, but I was hoping for something more sophisticated or systematic than advice that is essentially "add log messages, figure out what's going on, and fix it."  There are lots of tools out there for analyzing and documenting control-flow in single-threaded programs; is there nothing available for multi-threaded programs?    See also
1699
Is there a way to determine how many cores a machine has from C/C++ in a platform-independent way? If no such thing exists, what about determining it per-platform (Windows/*nix/Mac)?
7498
Back in the 90s when I first started out with MFC I used to dynamically link my apps and shipped the relevant MFC DLLs.  This caused me a few issues (DLL hell!) and I switched to statically linking instead - not just for MFC, but for the CRT and ATL.  Other than larger EXE files, statically linking has never caused me any problems at all - so are there any downsides that other people have come across?  Is there a good reason for revisiting dynamic linking again?  My apps are mainly STL/Boost nowadays FWIW.
50240
I try to watch how programs work by running them by the 'Qt Creator' debugger. For better orientation I'd like to see also the system (core) utilities fully in the call stack window as I am used from the MS Visual Studio 6.0, not only to see their assembly code. For the utilities, the 'Qt Creator' debugger displays only that their debug symbols are not available. (Sometimes, the system generates bug reports for its developers; the bug report dialog has requested installing such symbols only for a particular program.) How can I get the core debug symbols? (Without translating the whole Ubuntu version. I use the 'Update Manager' to install updates regularly. My /sys/kernel/debug/x86 directory contains only one empty file. I have not found it in the 'Ubuntu software center' nor do I see if some of the packages at the  is what I seek.) Thanks!
30349
I'm working on a large c++ system that is has been in development for a few years now. As part of an effort to improve the quality of the existing code we engaged on a large long-term refactoring project.  Do you know a good tool that can help me write unit tests in C++? Maybe something similar to Junit or Nunit?  Can anyone give some good advice on the methodology of writing unit tests for modules that were written without unit testing in mind?
110919
In a windows form application what is the impact of calling Thread.Sleep(1) as illustrated in the following code:  public Constructor() {     Thread thread = new Thread(Task);     thread.IsBackground = true;     thread.Start(); }  private void Task() {     while (true)     {         // do something         Thread.Sleep(1);     } }   Will this thread hog all of the available CPU?    What profiling techniques can I use to measure this Thread's CPU usage ( other than task manager )?
91216
Our project is running on Windows CE 6.0 and is written in C++ . We have some problems with the code , and we are unable to debug . We also found out that if in our application we create threads and try to printf from them , the output won't appear . The only output that will appear is the one from the main thread . I would like to do the following :   create a custom windows message use as it's WPARAM the address of a char* I want to show on the screen use as it's LPARAM the length of the char* I want to show on the screen send the message process it when it comes , so that it prints the char*   How could I create the custom windows message ? What are the types of WPARAM and LPARAM ? Is it possible to do what I just wrote ?  Thanks
97724
Crashing bugs can be the most annoying ones, leading to data loss, downtime and frustrated users. It would be good if applications crashed less.  Because of the complexity of the machine context, crashes often can't be reproduced in reasonable time for an ordinary user. That doesn't mean that the bug is rare - It could simply mean that the thing that triggers it occurs rarely for each user (for example DST changes). Such bugs are unlikely to be fixed unless a lot of users report them. It would be good if more crashes were reported.  To debug crashes, the developers need as much unambiguous context as possible. Generated crash reports are good, because they're usually detailed and accurate. Users can't be expected to zealously observe and report all the context manually, so they often submit sparse and wrong information.  The target audience for a lot of applications is not developers or sysadmins, but rather the general public, at home or at work. Such users can't be expected to know how to collect crash information manually, or to install -dbg packages, but generated reports from such users can still be usable. Some applications have their own crash reporting tools, but in my experience these rarely work, and when they report that they failed to report the error there doesn't seem to be any information on how to do it manually (I've observed this for recent versions of both Firefox and Flash). System-wide generation of crash reports would be good.  Is there any sort of crash report generation* which can be enabled globally** without installing a ton of -dbg packages, reading the documentation of each and every application, or slowing a normal machine down to a crawl?  * Logs, core dumps, stack traces, whatever  ** Not necessarily for init, but at least for a significant subset of the applications running on a typical desktop Linux installation. In my experience GUI applications crash 100+ times more frequently than shell applications, so GUI applications would naturally be the focus.
38501
I want to have a way to report the stack trace to the user if an exception is thrown. What is the best way to do this? Does it take huge amounts of extra code?  To answer questions:  I'd like it to be portable if possible. I want information to pop up, so the user can copy the stack trace and email it to me if an error comes up.
104984
What is the best (easiest) way to take a screenshot of an running application with C++ under Windows?
8699
How does one do this?  If I want to analyze how something is getting compiled, how would I get the emitted assembly code?
80463
One thing that annoys me when debugging programs in Visual Studio (2005 in my case) is that when I use "step over" (by pressing F10) to execute to the next line of code, I often end up reaching that particular line of code in a totally different thread than the one I was looking at. This means that all the context of what I was doing was lost.  How do I work around this?  If this is possible to do in later versions of Visual Studio, I'd like to hear about it as well.  Setting a breakpoint on the next line of code which has a conditional to only break for this thread is not the answer I'm looking for since it is way too much work to be useful for me :)
52358
I'm writing an application that can be started either as a standard WinForms app or in unattended mode from the command-line. The application was built using the VS 2k5 standard WinForms template.  When the application is executed from the command-line, I want it to output information that can be captured by the script executing the application. When I do this directly from Console.WriteLine(), the output does not appear, although it can be captured by piping to a file.  On the other hand, I can force the application to pop up a second console by doing a P/Invoke on AllocConsole() from kernel32. This is not what I want, though. I want the output to appear in the same window the application was called from.  This is the salient code that allows me to pop up a console from the command line:  &lt;STAThread()&gt; Public Shared Sub Main()      If My.Application.CommandLineArgs.Count = 0 Then         Dim frm As New ISECMMParamUtilForm()         frm.ShowDialog()     Else         Try             ConsoleControl.AllocConsole()             Dim exMan As New UnattendedExecutionManager(ConvertArgs())             IsInConsoleMode = True             OutputMessage("Application started.")             If Not exMan.SetSettings() Then                 OutputMessage("Execution failed.")             End If         Catch ex As Exception             Console.WriteLine(ex.ToString())         Finally             ConsoleControl.FreeConsole()         End Try      End If  End Sub  Public Shared Sub OutputMessage(ByVal msg As String, Optional ByVal isError As Boolean = False)     Trace.WriteLine(msg)     If IsInConsoleMode Then         Console.WriteLine(msg)     End If      If isError Then         EventLog.WriteEntry("ISE CMM Param Util", msg, EventLogEntryType.Error)     Else         EventLog.WriteEntry("ISE CMM Param Util", msg, EventLogEntryType.Information)     End If  End Sub
57856
I need a cross platform solution for clearing the console in both Linux and Windows written in C++. Are there any functions in doing this? Also make note that I don't want the end-user programmer to have to change any code in my program to get it to clear for Windows vs Linux (for example if it has to pick between two functions then the decision has to be made at run-time or at compile-time autonomously).
66029
I wrote C++ for 10 years. I encountered memory problems, but they could be fixed with a reasonable amount of effort.  For the last couple of years I've been writing C#. I find I still get lots of memory problems. They're difficult to diagnose and fix due to the non-determinancy, and because the C# philosophy is that you shouldn't have to worry about such things when you very definitely do.  One particular problem I find is that I have to explicitly dispose and cleanup everything in code. If I don't, then the memory profilers don't really help because there is so much chaff floating about you can't find a leak within all the data they're trying to show you. I wonder if I've got the wrong idea, or if the tool I've got isn't the best.  What kind of strategies and tools are useful for tackling memory leaks in .NET?
4251
How do I invoke a console application from my .NET application and capture all the output generated in the console?   (Remember, I don't want to save the information first in a file and then relist as I would love to receive it as live.)
77250
My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.  I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:     Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point   Huh?  Yes it does... and it was all working 15 min earlier.  Sure, I can believe that I accidentally hit something or done something before I closed it up... but what?  How do I troubleshoot this?    My Program.cs file looks like this:  using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading;  namespace SimpleAIMLEditor {     static class Program     {         [STAThread]         static void Main()         {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);              Application.Run(new mainSAEForm());         }     } }   ...and there are some comments in there.    There are no other errors.  Help?