I am using CentOS 6.3 64 bit and trying to develop a c++ application using IBM® Data Studio
Version 4.1.0.1 which is a flavor of eclipse. I have written a multithread application and all was going well till I tried to do file IO.
I used ofstream to write my data to a file . But this is not allowing me to debug this snippet of code, If I place any breakpoints it shows a break point can not be placed .
I have written this piece of code in a thread (pthread)
ofstream myfile;
char chFileName[100];
sprintf(chFileName,"Json_%s_%s_%d",strType,strGroupID,iIndex);
myfile.open (chFileName);
myfile << strJSON;
myfile.close();
Here is the console output before the application and thread terminates.
[Thread debugging using libthread_db enabled] [New Thread 0x7fffe9f1e700 (LWP 28380)] [New Thread 0x7fffe951d700 (LWP 28381)]
[Switching to Thread 0x7fffe951d700 (LWP 28381)] [Thread 0x7fffe951d700 (LWP 28381) exited] [Thread 0x7fffe9f1e700 (LWP 28380)
exited]
Is it not wise to perform file IO in a thread ?
Could someone please help me with how to fix this issue ?
Related
I used unordered_map and I started 3 worker threads in my C++ program. But when I used gdb to run my code, I found the following GDB debug info frequently and continually were showing up:
[New Thread 0x2aaac3dc6700 (LWP 4709)]
[Thread 0x2aaac3dc6700 (LWP 4709) exited]
[New Thread 0x2aaac3dc6700 (LWP 4710)]
[Thread 0x2aaac3dc6700 (LWP 4710) exited]
[New Thread 0x2aaac3dc6700 (LWP 4711)]
[Thread 0x2aaac3dc6700 (LWP 4711) exited]
.....................
How could so many threads were created and quickly destroyed, were there background threads for garbage collection of obsoleted objects(just like Java), I doubt if the unordered_map object caused so many threads to do clean for it.
I have the grpc route_guide example working on both aarch64 and x86_64 but when I translate this example into an already existing (CMake) project only x86_64 works. The aarch64 just hangs in server.BuildAndStart()
The code is identical for the 2 platforms:
void RunServer(const std::string& db_path) {
std::cout << "RunServer" << std::endl;
std::string server_address("0.0.0.0:50051");
RouteGuideImpl service(db_path);
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
//builder.SetSyncServerOption(ServerBuilder::SyncServerOption::MAX_POLLERS,2); // Doesn't make a difference
std::cout << "Before builder.BuildAndStart()" << std::endl;
std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
std::cout << "After builder.BuildAndStart()" << std::endl;
std::cout << "Server listening on " << server_address << std::endl;
server->Wait();
}
Using gdb I can see that x86_64 starts 1+4 threads and then listens for grpc traffic. It also works using any other example for route guide (e.g both in C++ and node) communicating with this.
(gdb) run
Starting program: /home/me/mycode/grpc_project/build/myexecutable
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffd0bd9700 (LWP 30537)]
RunServer
DB parsed, loaded 100 features.
Before builder.BuildAndStart()
[New Thread 0x7fffd03d8700 (LWP 30538)]
[New Thread 0x7fffcfbd7700 (LWP 30539)]
[New Thread 0x7fffcf3d6700 (LWP 30540)]
[New Thread 0x7fffcebd5700 (LWP 30541)]
After builder.BuildAndStart()
Server listening on 0.0.0.0:50051
But on the aarch64 platform only 1+2 threads are started then grpc hangs
Starting program: /home/ubuntu/mycode/grpc_project/build/myexecutable
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fab553030 (LWP 27568)]
RunServer
DB parsed, loaded 100 features.
Before builder.BuildAndStart()
[New Thread 0x7faad53030 (LWP 27569)]
[New Thread 0x7faa553030 (LWP 27570)]
Where to start debugging this and what could the root cause be?
Others (both here at SO and elsewhere) have suggested limiting the number of threads using ResourceQuota like this
grpc::ResourceQuota rq;
rq.SetMaxThreads(n); // n=1 or n=2
builder.SetResourceQuota(rq);
But it makes no difference, aarch64 still hangs
Ubuntu 16.04 with aarch64 (Nvidia TX2)
I had attached gdb to a long running process(>25 hours). To manage the session, I used screen on my Ubuntu machine. I could get the session back. I got back the gdb console. But on continuing I saw my process throw SIGABRT and exit followed up by other process exit messages.
[New LWP 122]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007fe8ef29ea15 in futex_abstimed_wait_cancelable (private=0, abstime=0x7ffc8c628420, expected=0, futex_word=0x7fe8e6378640) at ../sysdeps/unix/sysv/
linux/futex-internal.h:205
205 ../sysdeps/unix/sysv/linux/futex-internal.h: No such file or directory.
(gdb) c
Continuing.
(gdb) [Thread 0x7be8d8bfd700 (LWP 48) exited]
Thread 32 "my-process" received signal SIGABRT, Aborted.
[Switching to Thread 0x7be8d2bbd700 (LWP 60)]
0x00007fe8eece4428 in __GI_raise (sig=sig#entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) c
Continuing.
Couldn't get registers: No such process.
Couldn't get registers: No such process.
Couldn't get registers: No such process.
(gdb) [Thread 0x7be8b67ff700 (LWP 119) exited]
[Thread 0x7be8b49fe700 (LWP 122) exited]
...
I am not able to get the gdb console after that. Though I see a process running when I run ps -ef
root 133 0 1 Jan14 ? 00:26:09 gdb --pid=23
How do get back the console for this gdb process? I wanted to see the backtrace.
Or is there a better way to attach gdb to a long running process ?
I am compiling the unit tests (via GoogleTests) for my program and whenever I try to compile in DEBUG mode on Solaris 11.3 with Eigen 3.2.x, I'm getting this SIGSEGV error then core dump when running the program in gdb:
(gdb) r
...
[Thread debugging using libthread_db enabled] [New Thread 1 (LWP 1)]
Program received signal SIGSEGV, Segmentation fault. [Switching to
Thread 1 (LWP 1)] 0x0830fc30 in
Eigen::internal::ploadu (
from=0xfeffe5a0) at ./eigen/Eigen/src/Core/arch/SSE/Complex.h:307 307 {
EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu((const
double*)from)); }
(gdb)
When print from in gdb this is what I'm getting:
gdb p from: (const std::complex< double > *) 0xfeffe5a0
This SIGSEGV only on Solaris, and only when compiling with -Og. I've compiled and tested it on multiple other OSes and there are no issues whatsoever. Is this a known issue? It looks it has to do with some SSE optimizations and alignments, however I cannot pinpoint what exactly is going on.
This question already has answers here:
Why does java app crash in gdb but runs normally in real life?
(2 answers)
Closed 8 years ago.
I wrote a C++ program. It invokes some functions provided by libhdfs(HDFS API for C++, implemented with JNI) and it runs OK when normally executed. When I use gdb to launch the program and input run command. The program fails to run and I got the following error message in gdb context:
[Thread debugging using libthread_db enabled]
[New Thread 0x40100940 (LWP 18482)]
[New Thread 0x40201940 (LWP 18483)]
...
[New Thread 0x41514940 (LWP 18502)]
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaac26c862 in ?? ()
I use command shell echo $CLASSPATH in gdb context. It shows the correct HDFS related environment.
I searched with Google and StackOverflow. But I did not get any idea.
Any tip?
Why does java app crash in gdb but runs normally in real life? provided a solution:
handle SIGSEGV nostop noprint pass
While, it is not so elegant.