Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.7.1 C++ target has new Multithread issue #2210

Closed
alainmarcel opened this issue Jan 24, 2018 · 9 comments
Closed

4.7.1 C++ target has new Multithread issue #2210

alainmarcel opened this issue Jan 24, 2018 · 9 comments
Milestone

Comments

@alainmarcel
Copy link

Hi Mike,
I'm doing my developement on 4.7, but I gave a try to the 4.7.1 C++ target:

  • Note, there are new gcc compiler warnings, 4.7 was warning free,
  • There is a new multithread issue around:

dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState previousD, size_t t) {
dfa::DFAState
retval;
auto iterator = previousD->edges.find(t);
retval = (iterator == previousD->edges.end()) ? nullptr : iterator->second;
return retval;
}

I have been trying to play with the read and write locks in the methods of that class, but it seems the problem is pervasive, if I add locks, I can go a bit further but the overall locking mechanism probably lacks complete testing, hence this is not yet multi-thread safe.

Can you address this? My setup is really complex, would be hard to give you a testcase but we could work on that.

Thanks
Alain

@alainmarcel
Copy link
Author

An example stack trace:

#0 0x0000000000fd2ed0 in __gnu_cxx::__normal_iterator<std::shared_ptrantlr4::atn::ATNConfig*, std::vector<std::shared_ptrantlr4::atn::ATNConfig, std::allocator<std::shared_ptrantlr4::atn::ATNConfig > > >::__normal_iterator (this=0x7ffff5164300, _i=@0x8: ) at /usr/include/c++/5/bits/stl_iterator.h:741
#1 0x0000000000fd209c in std::vector<std::shared_ptrantlr4::atn::ATNConfig, std::allocator<std::shared_ptrantlr4::atn::ATNConfig > >::begin (this=0x8) at /usr/include/c++/5/bits/stl_vector.h:548
#2 0x0000000000fefb85 in antlr4::atn::ParserATNSimulator::computeReachSet (this=0x7ffff00360f0, closure
=0x0, t=36, fullCtx=false) at /home/alain/antlr4/antlr4-4.7.1/runtime/Cpp-Debug/runtime/src/atn/ParserATNSimulator.cpp:453
#3 0x0000000000feef1b in antlr4::atn::ParserATNSimulator::computeTargetState (this=0x7ffff00360f0, dfa=..., previousD=0x7fffe8032f90, t=36) at /home/alain/antlr4/antlr4-4.7.1/runtime/Cpp-Debug/runtime/src/atn/ParserATNSimulator.cpp:269
#4 0x0000000000fee58d in antlr4::atn::ParserATNSimulator::execATN (this=0x7ffff00360f0, dfa=..., s0=0x7fffe8032f90, input=0x7ffff0000bd0, startIndex=0, outerContext=0x7ffff0036230) at /home/alain/antlr4/antlr4-4.7.1/runtime/Cpp-Debug/runtime/src/atn/ParserATNSimulator.cpp:164
#5 0x0000000000fee3d1 in antlr4::atn::ParserATNSimulator::adaptivePredict (this=0x7ffff00360f0, input=0x7ffff0000bd0, decision=23, outerContext=0x7ffff0036230) at /home/alain/antlr4/antlr4-4.7.1/runtime/Cpp-Debug/runtime/src/atn/ParserATNSimulator.cpp:140

@jrobsonchase
Copy link
Contributor

jrobsonchase commented Jan 29, 2018

Can confirm - I'm seeing this issue as well after upgrading to 4.7.1 to fix a memory leak issue.

My stack trace is pretty much identical.

Edit: also, my old demo from the first time this issue came up shows the issue after being updated to 4.7.1: https://github.com/jechase/antlr_cpp_threads

@jrobsonchase
Copy link
Contributor

@mike-lischke any updates on this?

@mike-lischke
Copy link
Member

Can you try my pending patch #2177? That solved all my multi threading issues so far.

@jrobsonchase
Copy link
Contributor

@mike-lischke Looks like that worked! No threading or memory leak issues :)

@alainmarcel
Copy link
Author

Confirmed, works great! Huge memory savings too.
Thanks
Alain

@mike-lischke
Copy link
Member

I wonder why you see mem leak fixes, however. There isn't anything in the code that would take care for memory beyond what was there before.

@parrt I think this patch can be merged, now that we have 2 other confirmations it does what it is supposed to do. That way interested developers get a thread safe runtime right with the first download of the branch. And it's a pretty important fix (#2177).

@parrt parrt added this to the 4.7.2 milestone Mar 1, 2018
@jrobsonchase
Copy link
Contributor

I saw the memory leaks in 4.7.0 and the threading issue in 4.7.1, where the leaks had (presumably) been fixed. So with this to address the threading issues, all problems are solved! At least as far as I'm aware.

@Krzmbrzl
Copy link
Contributor

@parrt I assume this can be closed now

@parrt parrt closed this as completed Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants