Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » thread bug....and fix
thread bug....and fix [message #52160] Tue, 30 July 2019 14:53 Go to next message
aftershock is currently offline  aftershock
Messages: 137
Registered: May 2008
Experienced Member
Hi,
Bug report.
It seems that
handle can be 0 at unexpected places,
So I added additional checks for that to fix.
See added lines.
Wait function got stuck at WaitForSingleObject when handle was 0.
int Thread::Wait()
{
	if(!IsOpen())
		return -1;
	int out;
#ifdef PLATFORM_WIN32
	dword exit;
	if(!GetExitCodeThread(handle, &exit))
		return -1;
	if(exit != STILL_ACTIVE)
		out = (int)exit;
	else
	{
		if (!IsOpen())  // ADDED THIS LINE
		   return Null;	
		if(WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0)
			return Null;
		if (!IsOpen()) // ADDED THIS LINE
		   return Null;	
		out = GetExitCodeThread(handle, &exit) ? int(exit) : int(Null);
	}
	Detach();
#endif
#ifdef PLATFORM_POSIX
	void *thread_return;
	if(pthread_join(handle, &thread_return))
		out = Null;
	else
		out = (int)(intptr_t)thread_return;
	handle = 0;
#endif
	return out;
}

[Updated on: Wed, 31 July 2019 12:55]

Report message to a moderator

Re: thread bug....and fix [message #52167 is a reply to message #52160] Wed, 31 July 2019 12:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12020
Registered: November 2005
Ultimate Member
Would be nice to show some example of "unexpected place".

Also I would rather have a copy of the whole file than unformated text Smile

Mirek
Re: thread bug....and fix [message #52169 is a reply to message #52167] Wed, 31 July 2019 12:57 Go to previous messageGo to next message
aftershock is currently offline  aftershock
Messages: 137
Registered: May 2008
Experienced Member
It is where I added the lines.
GetExitCodeThread(handle....
handle was 0 in the debugger.
Application Verifier... detected those things.

[Updated on: Wed, 31 July 2019 13:00]

Report message to a moderator

Re: thread bug....and fix [message #52177 is a reply to message #52169] Fri, 02 August 2019 11:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12020
Registered: November 2005
Ultimate Member
aftershock wrote on Wed, 31 July 2019 12:57
It is where I added the lines.
GetExitCodeThread(handle....
handle was 0 in the debugger.
Application Verifier... detected those things.



I mean, what is your code?

Somehow I fail to grasp how calling Wait with NULL handle could have happened.

To be more specific, as long as there is no catastrophic failure of client code, handle can get 0 in 3 ways:

- thread creation fails. Why do you call Wait in that case?
- Detach is called. Why do you call Wait in that case?
- no attempt to start thread (default constructor). Why do you call Wait in that case?

So I am really curious what has happened here. In other words, if above patch is really fixing something, then this requires much more careful investigation because it would mean many things are not what they should be.....

(Ideally, testcase package demonstrating the problem would be welcome).


Mirek

[Updated on: Fri, 02 August 2019 11:40]

Report message to a moderator

Re: thread bug....and fix [message #52180 is a reply to message #52177] Fri, 02 August 2019 19:28 Go to previous messageGo to next message
aftershock is currently offline  aftershock
Messages: 137
Registered: May 2008
Experienced Member
Could debugger display false values?

Is that class multithreaded?
Re: thread bug....and fix [message #52181 is a reply to message #52180] Sat, 03 August 2019 11:23 Go to previous message
mirek is currently offline  mirek
Messages: 12020
Registered: November 2005
Ultimate Member
aftershock wrote on Fri, 02 August 2019 19:28
Could debugger display false values?


Can happen. When in doubt, use DUMP/RDUMP/DDUMP.

Quote:

Is that class multithreaded?


Of itself, no.
Previous Topic: Unable to run exe file in windows
Next Topic: GTK backend now requires hb.h to be presented in include paths (Manjaro)
Goto Forum:
  


Current Time: Fri Sep 20 03:23:12 CEST 2019

Total time taken to generate the page: 0.01678 seconds