Code Monkey home page Code Monkey logo

Comments (18)

gempa-jabe avatar gempa-jabe commented on September 13, 2024 1

Yes, before delete.

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

Maybe a _thread->join() is required prior to deleting it. Can you try that? I think that std::thread is more sensitive to that than boost::thread.

from common.

gilcel avatar gilcel commented on September 13, 2024

OK thanks but where should I place _thread->join() exactly ?
In Timer::Loop at line: 355, so before the delete _thread ?

from common.

gilcel avatar gilcel commented on September 13, 2024

Unfortunately it crashes with error (in Terminal):
libc++abi: terminating due to uncaught exception of type std::__1::system_error: thread::join failed: Resource deadlock avoided

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

Then we have to test the code and fix it. If you need it right now, you can revert the commits which replaced boost with std.

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

Regarding your question regarding testing: we only test on Linux. All other platforms are experimental for which we do not provide builds.

from common.

gilcel avatar gilcel commented on September 13, 2024

If I comment out the part then no crashes anymore, but I'm aware that we get a memory leaks:

#if ( _thread ) {
#  _thread->join();
#   delete _thread;
#  _thread = nullptr;
#	}

So I moved it to Timer::deactivate() and when I close the window by clicking on the red button of a GUI-app like scrttv then the _thread gets properly deleted.

#if !defined(SC_HAS_TIMER_CREATE)
bool Timer::deactivate(bool remove) {
	assert(_isActive == true);

	_isActive = false;

	if ( remove ) {
		const std::lock_guard<std::mutex> lk(_mutex);

		for ( TimerList::iterator it = _timers.begin(); it != _timers.end(); ++it ) {
			if ( *it == this ) {
				_timers.erase(it);
				break;
			}
		}
		
	}
	
	if ( _thread ) {
		printf("DEBUG: Calling _thread->join\n");
		_thread->join();	
		delete _thread;
		_thread = nullptr;
	}

	return true;
}

Could this be the solution ?

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

It only works if there is only one timer. Two or more timers won't work. Under BSD exists the callout API for timers. But I cannot test it due to the lack of access to such systems.

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

The issue is that you are not allowed to delete a thread within a running thread. I could reproduce it and trying to fix it.

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

Actually your fix was almost correct, I have corrected it slightly. Please give it a try.

from common.

gilcel avatar gilcel commented on September 13, 2024

OK will test it...also shouldn't the thread be checked if it is joinable and then call detach() ? This works for me in the Timer::Loop

if(_thread->joinable() ){
		_thread->detach();	
		//delete _thread;
		//_thread = nullptr;
	}

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

joinable() could be checked in the code I have changed, prior to join().

from common.

gilcel avatar gilcel commented on September 13, 2024

Your code works now! thanks! No more crashes! But yes I changed:

if ( _timers.empty() && _thread {
...
}

to:

if ( _timers.empty() && _thread->joinable() ) {

}

Is this correct ?

Also would it be better to use std::this_thread::sleep_for(std::chrono::seconds(1)); in Timer::Loop instead of Core::sleep()?
Does Core::sleep() use usleep() ?

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

_thread might be nullptr, the check is required. Add joinable() as condition for join(). Feel free to play with different sleep methods.

from common.

gilcel avatar gilcel commented on September 13, 2024

Ok this should be better:

if ( _timers.empty() && _thread ) {
		if(_thread->joinable() ){
			_thread->join();
			delete _thread;
			_thread = nullptr;
		}	
	}

from common.

gempa-jabe avatar gempa-jabe commented on September 13, 2024

Almost ... it has to be deleted, whether joined or not.

from common.

gilcel avatar gilcel commented on September 13, 2024

Strangely enough it never gets into this part of code in Timer::deactivate when closing a GUI-app or making an seiscomp update-config... Changed again:

if ( _timers.empty() && _thread ) {
		printf("DEBUG: _timers.empty() && _thread  ?");
		
		if(_thread->joinable() ){ 
			_thread->join();
		}
		
		printf("DEBUG: Delete thread");	
		delete _thread;
		_thread = nullptr;
			
	}

from common.

gilcel avatar gilcel commented on September 13, 2024

Thanks for your fixes with commits:
c94241f
bd650c5

No more Timer related crashes for macOS.
This issue can be closed.

from common.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.