-
Notifications
You must be signed in to change notification settings - Fork 105
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
[Bug] Crash while thread running after FileWatcherInotfiy destructed. #157
Comments
Hi! #include <efsw/efsw.hpp>
int main( int argc, char** argv ) {
efsw::FileWatcher* fileWatcher = new efsw::FileWatcher();
fileWatcher->watch();
delete fileWatcher;
return 0;
} Neither with a watched dir: #include <efsw/efsw.hpp>
#include <iostream>
class UpdateListener : public efsw::FileWatchListener {
public:
UpdateListener() {}
void handleFileAction( efsw::WatchID, const std::string&, const std::string&, efsw::Action,
std::string ) {}
};
int main( int argc, char** argv ) {
efsw::FileWatcher* fileWatcher = new efsw::FileWatcher();
UpdateListener* ul = new UpdateListener();
fileWatcher->addWatch( ".", ul );
fileWatcher->watch();
delete fileWatcher;
delete ul;
return 0;
} I'm missing something? |
I just want to make someone getting main code path and why it crashed,which does not means i use filewatcherinotfiy directly. |
In my usage scenario, it will appear once about an hour running. Especially in the case of high load machine, pthread_create returns does not mean that the thread has been created and run entry point function successfully. Actually you can deduce it from the way the code runs, which is indeed possible. |
Oh, I understand. I thought that your code snipped was a literal example. |
Let me know if the last commit helps with your issue. |
I pack this commit to my program but still crashed. So perhas it not works yet. |
Sorry, the fix I sent was for another kind of error and also was worst than before. I misinterpreted the crash completely. I think that now I have a clear picture of the issue but I have no idea how I can avoid it in 100% of the cases. |
Also: I tried to replicate it by doing something stupid like: int main( int argc, char** argv ) {
int c = 0;
UpdateListener* ul = new UpdateListener();
while ( c++ < 10000 ) {
efsw::FileWatcher* fileWatcher = new efsw::FileWatcher();
fileWatcher->addWatch( ".", ul );
fileWatcher->watch();
delete fileWatcher;
}
delete ul;
return 0;
} And pthread_join is doing its job, it always waits for the |
I'm going to figure out the root cause of this issue and upload lastest clues ASAP. |
Maybe using c++11 threads helps? |
maybe try my PR that uses c++11 primitives for threading and locking: |
Thanks for the collaboration. It seems that still needs some work to compile properly. You had this same issue? Because I wasn't able to reproduce it yet. |
what needs work? I have no problem comliling? |
no i did not, but the report somewhat lowered my trust in the hand rolled thread management, thus I pulled in the c++11 stuff, which I think is the best approach |
Perphas it's better way to use standard thread library. Actually it's weird and no more detail information or core dump can be digged out. |
I agree, efsw was using custom thread implementation because it was created actually before C++11 and I kept compatibility for older compilers until just recently. But know it's possible to migrate everything to C++11 standard headers. The PR looks OK but I'll not merge it until I have enough time to test it on all platforms. |
My main instruction likes
There are two threads cross running in process,
We found watcher thread crashed and this backtrace remained:
main thread stack :
According to above stackes, it's watcher deletion happened before watcher entry_point running, which means
m_objest
had been deleted and memory undetected in that timeThe text was updated successfully, but these errors were encountered: