How to Kill the Worker Thread ?
-
ParagPatel wrote:
if(stopTh == true)
Unless
stopTh
isvolatile
, the compiler will optimize out this check."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
Thanks , Yes.. stopTH must be globle or thread function must use through passed class object.
Parag Patel Sr. Software Eng, Varaha Systems
-
Thanks , Yes.. stopTH must be globle or thread function must use through passed class object.
Parag Patel Sr. Software Eng, Varaha Systems
ParagPatel wrote:
Thanks Simmons,
:confused:
ParagPatel wrote:
Yes.. stopTH must be globle
Being global has nothing to do with it. If the compiler detects that nothing in the loop is changing that variable, it will optimize out the check. So even if the secondary thread changes that variable, it will go unseen.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Thanks , Yes.. stopTH must be globle or thread function must use through passed class object.
Parag Patel Sr. Software Eng, Varaha Systems
Changing it through the class object = changing it from a different thread (the main thread of the app). Which means it will be optimized away.
It is a crappy thing, but it's life -^ Carlo Pallini