U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » Thread::ShutdownThreads not safe
Thread::ShutdownThreads not safe [message #26951] Sun, 13 June 2010 15:40 Go to previous message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
Hi,

I think the implementation of Thread::ShutdownThreads() and Thread::IsShutdownThreads() is not thread-safe:

static Atomic  sShutdown;

void Thread::ShutdownThreads()
{
	AtomicInc(sShutdown);
	while(sThreadCount)
		Sleep(100);
	AtomicDec(sShutdown);
}

bool Thread::IsShutdownThreads()
{
	return sShutdown;
}

I believe that the correct implementation would be:

static volatile Atomic  sShutdown = 0;

void Thread::ShutdownThreads()
{
	AtomicInc(sShutdown);
	while(AtomicRead(sThreadCount))
		Sleep(100);
	AtomicDec(sShutdown);
}

bool Thread::IsShutdownThreads()
{
	return AtomicRead(sShutdown);
}


Could you please look into this, and fix if I am correct.
Thanks,
- Sandor
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: double equals nothing
Next Topic: DeXml() incomplete
Goto Forum:
  


Current Time: Tue Jul 21 10:57:07 GMT+2 2026

Total time taken to generate the page: 0.00921 seconds