Error in <TReentrantRWLock::WriteUnLock>: Write lock already released TThread member function

I have an CMake standalone application using ROOT TThreads.

I have followed what is suggested by GSI, point 6.1 How to Use the ROOT TThread to use a custom class with a member function.

When I start the thread, I get this warning:
Error in <TReentrantRWLock::WriteUnLock>: Write lock already released for 0x560b57ac93f8

What does it mean? Is it a problem? The program works fine.

The issue arises when I call the inside the static void* handle function a non-static member function of the MyThreadClass (derived from TThread) as follows:

void *MyThreadClass::handle(void *ptr) {
    MyThreadClass* const thread = static_cast<MyThreadClass *>(ptr);
    return nullptr;

which is simlar to How to Use the ROOT TThread
or c++ - Constructing thread executing a member function of a derived class - Stack Overflow

MyThreadClass* thread has the address 0x560b57ac93f8, matching with the warning message.

Thanks for the help!

ROOT Version: 6.23/01
Platform: Ubuntu 18
Compiler: gcc

Maybe @eguiraud can have an idea…

TThread is legacy/deprecated in favor of std::thread, I’m afraid I don’t know much about its internals. We need @pcanal . With that said:

It looks like a bug in either TThread or ROOT’s TReentrantRWLock: it might not be a problem for your program but we definitely don’t want that to happen in general, in ROOT. It would be nice if you could provide a reproducer.


When in the process did you call ROOT::EnableThreadSafety() ?

1 Like

That is very weird. The object type printing the message is TReentrantRWLock which (unless you inherited from that internal type!) is not the case of your thread object. This would indicate that there is somewhere a memory error … (maybe the static case is wrong … humm still odd … maybe you could provide a complete running (and thus failing) example)

I must have misread the address, because I checked the address, and they do not match now. Sorry about that.

Here is what my debugger shows about how this function is reached when I click on the ‘Start’ TGButton:

I will try to generate a minimum working example.

This solves it! Thanks so much.

I did not know about this ‘magic’ statement. I did not find it in the manual I was following: Chapter: Threads

Maybe it can be added to it ? See also TThread documentation outdated · Issue #7216 · root-project/root · GitHub

Is there any rule when to call it? At program beginning?

Thanks again!

It must be called before the start of any threads. Calling it at the program beginning is indeed a safe place.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.