debug multi-threaded programs tips [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I wonder how to debug multi-threaded programs effectively.
What I've done so far:
I read some gdb reference, but all of them talk little about multi-thread debuging.
I used gdb to debug my c++ programs.
linux thread reference
What's your tricks to share?
Skills
1> Understand the code structure well. 2> Debug thread by thread. 3> In terms of exact time-stamps implemented.
PS: The approch still cannot solve my problem.

Disable watchdog
Assign each thread a unique id/name. This way you may get thread id inside any function and know for sure what thread executes it.
Learn how to use Threads Window in Visual Studio:
http://msdn.microsoft.com/en-us/library/w15yf86f.aspx

Using the debugger to understand a program might work well for single threaded systems.
It definitly doesn't work (well) for problems involving more then one thread. This is per design, as human nature is single threaded.
So to get into a multithreaded system:
Identify all threads and how they depend on another by reading and understanding the sources.
Debug each thread on its own. This might imply disabling or synchronising other threads.
Add detailed logging in terms of exact time-stamps implemented to not add synchronisation to the threads
This approach follows the paradigm of doing one thing at a time.

Related

Can Python ever be faster than C in C based OS? Why? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
If Python was coded(based) on C then can Python ever surpass the C?
I know that the next stages be assembly, binaries when they communicate with OS and hardware. I have two assumptions that since most of the Operating Systems were coded in C then if the any code works on top of that OS, it is not possible that Python can be faster.
All things being equal, code running in an interpreter will execute more slowly than code running natively. However, things are rarely equal, and while I can't think of an example offhand, I would not be surprised if there were circumstances where a Python solution could execute faster than a C-based one (it'd probably be pretty esoteric, though).
Beyond that, raw execution speed is only one metric, and it's not the most important. It doesn't matter how fast your code is if it does the wrong thing, or nukes a server if someone sneezes, or exposes your system to malware, or it takes you a year to deliver a solution.
Python provides a bunch of high-level abstractions and tools that C doesn't, leading to faster development time (which is where the expense really is). You don't have to worry (as much) about memory leaks, buffer overruns, etc.
There is no such thing as a silver bullet, and no language is best at all things. There are times when a C-based solution is the right answer, and there are times when a Python-based solution is the right answer.

Is it better for me to use a for loop in Bash or C? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I'm writing a program to "break" one of my company's devices. The issue is that too much TCP traffic on the device shuts its port down and we need to try to replicate this. Originally, my thought has been to use the for loop in C, but I also think it's probably more representative of the failures that are occurring if there are more simultaneous connections. So my thought now is to create a bash script that will execute the program multiple times.
The real issue is that we are seeing the failures occur because TCP connections are being opened and closed for every command that comes in.
So I have a simple C program that opens a connection, sends a command to the device, gets the response, and then closes the connection. My original thought was to create a for loop inside the C code that performs all the connections, but it wouldn't happen simultaneously. So I wonder how much, if anything I lose with a bash script that executes the compiled C program in the for loop.

Multi thread write to database in c++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to use multithread to write data to MSSQL database in C++. Can I do it?
I think It can deadlocked or we must to wait. But I still want use multithread. Any idea?
Can I do it?
Can you program or are you willing to learn it? Because the "I" in the question is the critical thing. What you ask for is technically possible - but I have no idea whether you are capable of it.
I think It can deadlocked or we must to wait.
Generally every multi threaded data access MAY deadlock or wait. Which includes multi machine access - i.e. have hundreds of users accessing one database. Is there a question in there? The approaches to avoid deadlocks are well documented. Wait (i.e. wait for a writable lock) is also well documented.
But I still want use multithread. Any idea?
Learn enough programming to "just do it". Because this really is it - just do it.

Redirect messages directed at the GPU [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Is there anything as low level as that on any Linux distribution? My overall goal is to redirect the message (instruction) meant for the GPU.
That means I would have to be able to program a driver between the CPU and the GPU which redirects any message to where I'd like (like a packet sniffer, but for GPU instructions and one that would stop the info there).
Is there any native Linux support for this kind of thing? Where do I start and what OS is most recommended for this kind of access?
You would need to modify the GPU driver. There you can insert logging or whatever other redirection you have in mind. Since many graphics drivers on Linux are open-source, this should be possible for many graphics cards. But take note that it won't be portable--you'll need to write some separate code for each major variant of GPU you want to support.
If you have something more specific, like that you're trying to capture OpenGL commands, that might make things easier.

Performance Test in same condition [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have program in C and I want to test performance of my code! But I want change and test again and again! I want to run all of test in exactly same condition(same memory available, in general same resource available).
I am developing on MacOS 10.9 but I need tool works on both mac an linux!
Could you suggest any?
Thanks!
You could use the time(1) command:
time yourprogram yourarguments....
and you could limit resources with e.g. setrlimit(2), concretely using the ulimit shell builtin. See this.
Notice that the operating system kernel is providing resources (and can be seen as a resource itself, or at least as a resource manager). So with different OSes you cannot have exactly the same resources (and conditions)! For instance, file systems and scheduling are different on Linux and on MacOSX, and they are an important resource provided and managed by the OS kernel.
in your case if performance means execution time, then simple shell script like
date
your c file execution
date
this will tell you the required output.
if you need actual performance (time,cpu,memory,etc) then on Linux sar utility can be used which will provide all the performance counters.
after which you can analyze the data and get the performance of your code
use profilers for your code which will tell you performance of your code with suggestions if any are present
use static code analyzers (feed your code as input to code analyzer which will tell you the performance of your code and possible enhancements)

Resources