TFile problem with TThread?!

Hi everyone,

I got a problem with a TFile object during running my root application. The setup of my application looks like this:

  • got a main method which provide global data containing a TFile object
  • global data is protected with a TSemaphore
  • the main method starts two TTreads
  • a gui thread with a start and a stop button for the “work thread”
  • the work thread is running fine when I push the start button
  • but when I push the stop button, which just set a start/stop flag for the working thread in the global data. My working thread stops at points like TFile::Write() or TFile::Get(), which has nothing to do with my stop mechanic .

Now I try to create a example program to show you the error but this already stops when creating a new TFile?

Someone got an idea what I’m doing wrong?

Cheers
Benni

[quote]Someone got an idea what I’m doing wrong?[/quote]Not really, this looks fine on the surface. What are the stack trace of where the thread unexpectedly stop?

Philippe.

Hi Philippe,

here the stack trace of my program:

Obtained 6 stack frames.
rootAnalyser(_ZN17TControlFunctions12SaveRootFileEv+0x59) [0x8074f2f]
rootAnalyser(_ZN13TExtraction5StartEv+0xfc) [0x806e8ec]
rootAnalyser(_Z12startExtractPv+0x50) [0x8056b48]
/opt/root/lib/libThread.so(_ZN7TThread8FunctionEPv+0x8d) [0x41dc0c9d]
/lib/libpthread.so.0 [0x4259bc60]
/lib/libc.so.6(__clone+0x57) [0x426c7b77]

Hope it’s useful and enough? Never create my own stack trace output before.

Cheers

Benni

Hi,

The stack trace seems to indicate that the crash is in your code, could the problem be there?

Philippe.

Hi,

of course the problem could be in my code, but I and two associates didn’t find anything?!? That is why I post the topic here.

What hints can I get out of the stack trace? It’s a little bit cryptic to me.

Benni

Hi,

I recommend you try running your example under gdb. I.e. if you start you example with./mycode 123 abcdogdb --args ./mycode 123 abc gdb> run .... segfault appears ... gdb> where which (especially if you build your code with the -g option) would give you the line number where the crash happens. The stack trace you gave says that the crash happened in the routine:echo _ZN17TControlFunctions12SaveRootFileEv | c++filt TControlFunctions::SaveRootFile()

Cheers,
Philippe.

Hi,
I rebuild my project a little bit, because I thought I had a problem in my program structure. Now my TFile object is created in the thread, which use it exclusive. No other thread is now using the object.

Now when I first start my program after a reboot of the system I get the segmentation violation below, when I start the program a second time it is running “fine”, except of my old problem.

Do I handle the TFile object wrong?

Cheers
Benni

Why are my attachments not added??
segmentation violation.txt (4.97 KB)
Class InitRootFile.txt (2.66 KB)

[quote]Why are my attachments not added??[/quote]No sure, it might have a ‘dangerous’ extension or it might be too large. One way around both is to place your code on a web server (or on afs) where we can download it.

[quote]Do I handle the TFile object wrong?[/quote]No idea :slight_smile: We would need to see your code. You might also see the problem by running your case under valgrind (see valgrind.org).

Cheers,
Philippe.

I took a older version of my program and add step by step the new parts until my current version.

The last version which work has the following construction:

  • parent thread which creates:
  • the working thread
  • and a thread for a text menu

Next step was to change the text menu by a GUI with the same functions (start/stop the working thread). Here occurs the problems which I described in my first posed.

I will throw out the code parts which are not necessary and post the code later today or tomorrow. And thanks for the valgrind hint, I will try it.

EDIT Code added.

  • in globalDef.h the different versions can be set on/off
  • the error occurs when using TControlFunctions::InitParamTable() without TFile::Write() works fine
  • with TControlFunctions::InitParamTable() it crashes when I want to stop the program
    EDIT

Cheers
Benni
rootTmAnalyser_v0.2_rebuild.tar.gz (9.83 KB)

Hi,

For me your example fails with:[quote]Error in TMySQLServer::TMySQLServer: Code: 2002 Msg: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

  • ERROR: Can not connect to the MySql server[/quote]

Cheers,
Philippe.

Oh sry, forget to take out the mySQL functions. Replaced it with dummys.
rootTmAnalyser_v0.2_rebuild_1.tar.gz (9.2 KB)

Hi,

Please note the following C++ syntax errors: TControlFunctions.h:43: error: extra qualification ‘TControlFunctions::’ on member ‘Init’ TControlFunctions.h:44: error: extra qualification ‘TControlFunctions::’ on member ‘SaveRootFile’ TControlFunctions.h:63: error: extra qualification ‘TControlFunctions::’ on member ‘InitRootFile’ TControlFunctions.h:64: error: extra qualification ‘TControlFunctions::’ on member ‘InitParamTable’

Philippe.

Hi,

I was able to compile and run the code, but I fail to make it crash. Can you remind which exact setting I need to use and which exact step I need to take to get to the crash?

Thanks,
Philippe.

Hi Philippe,

Set

#define FUNTIONAL_VERSION_1 0
#define FUNTIONAL_VERSION_2 0

in globalDef.h. Program should crash when pushing stopbutton.
When it not does could it be because I use root v5.24?

Cheers
Benni

Hi,

I can’t reproduce the problem with the trunk.

[quote]When it not does could it be because I use root v5.24?[/quote]Can you try with the trunk or at least v5.27/06?

Cheers,
Philippe.

Hi,

I try to install the new root version, but make stops with:

XrdPosixXrootd.cc: In static member function static int XrdPosixXrootd::Statfs(const char*, statfs*)': XrdPosixXrootd.cc:1210: error: 'struct statfs' has no member named 'f_frsize' make[5]: *** [../../obj/XrdPosixXrootd.o] Fehler 1 make[4]: *** [Linuxall] Fehler 2 make[3]: *** [all] Fehler 2 make[2]: *** [XrdPosix] Fehler 2 make[1]: *** [all] Fehler 2 make[1]: Leaving directory/opt/root_v5.27.06/net/xrootd/src/xrootd’
*** Error condition reported by make (rc = 2):
make: *** [net/xrootd/src/xrootd/LastBuild.d] Fehler 1
rm core/utils/src/RStl_tmp.cxx core/utils/src/rootcint_tmp.cxx

[quote]I try to install the new root version,[/quote]On which platform/compiler? Can you try the trunk?
Alternatively, if you do not need xrootd, disable it for now (configure … --disable-xrootd …)

Cheers,
Philippe.

Good morning Philippe,

  • I’m working with suse Linux 8.2 (can’t use a newer Linux because of company software which only works with the old kernel) and the GNU C++ compiler (3.3-23)

  • same failure with the trunk

  • was able to install root v5.27.06 with the option, but no effect :frowning: same as before.

Cheers
Benni

Hi,

nobody any new ideas so fare?

I thought about another thing which might cause the problem:

Could it be that a TFile object of one thread has problems to work when in another thread (GUI) a polling loop like this below is running:

do{ // wait until other thread is finished
semaphore->Wait();
OTHER_THREAD_IS_DOING_FLAG = globalData.OTHER_THREAD_IS_DOING_FLAG;
semaphore->Post();
sleep(1);
}while(OTHER_THREAD_IS_DOING_FLAG != THREAD_DO_IDLE);

Cheers,
Benni