Re: Possible huge clue into unmanged/managed problem
From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 02/01/05
- Next message: Alvin Bruney [MVP]: "Re: Possible huge clue into unmanged/managed problem"
- Previous message: Jason Cartwright: "StackOverflowException with unmanaged memcpy"
- In reply to: cody: "Re: Possible huge clue into unmanged/managed problem"
- Next in thread: cody: "Re: Possible huge clue into unmanged/managed problem"
- Reply: cody: "Re: Possible huge clue into unmanged/managed problem"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Feb 2005 21:18:52 +0100
If you happen to abort a thread asynchronously, that means an exception can
bet thrown at any moment during program execution, you possibly have
corrupted the application state.
Consider following thread procedure
void SomeProc()
{
lock(myLock)
{
}
}
, when the exception is thrown during the execution of the finalize clause
(compiler generated from lock()), chances are that the lock is not released.
If it happens that you are executing unmanaged code during Abort, chances
are that locks held by your unmanaged code will not being released, buffers
not freed, semaphores not cleared etc.
If it happens during managed execution of global state initialization
(static's), you'll end with incorrectly initialized global state.
So, I think it's clear there is no other option then to exit the process or
throw away the application domain.
Not sure what you mean with:
terminate the last thread in an application shouldn't the process be
> terminated automatically by the system?
>
calling Thread.Abort on your current thread, is a synchronous Abort
(synchronous exception), and yes if it happens on the last managed thread in
the application, the CLR will shutdown the process.
Willy.
"cody" <deutronium@gmx.de> wrote in message
news:%23skSu%23ICFHA.268@TK2MSFTNGP10.phx.gbl...
> What do you mean with "terminate the process"? Why should I have to
> terminate the whole application if I only want to terminate one thread?
> And if a terminate the last thread in an application shouldn't the process
> be terminated automatically by the system?
>
> "Willy Denoyette [MVP]" <willy.denoyette@pandora.be> schrieb im
> Newsbeitrag news:OO1bdOHCFHA.4004@tk2msftngp13.phx.gbl...
>>
>>
>> "cody" <deutronium@gmx.de> wrote in message
>> news:u089dKGCFHA.3092@TK2MSFTNGP10.phx.gbl...
>>> You simply have to call return from the thread method to terminate a
>>> thread
>>> the clean way.
>>>
>>
>> And what if the thread is blocked or is in an infinite loop?
>> There is nothing wrong with Thread.Abort as long as you call it
>> synchronously. When called asynchronously you have to terminate the
>> process when done or unload the application domain if not running in the
>> primary domain.
>>
>> Willy.
>>
>
>
- Next message: Alvin Bruney [MVP]: "Re: Possible huge clue into unmanged/managed problem"
- Previous message: Jason Cartwright: "StackOverflowException with unmanaged memcpy"
- In reply to: cody: "Re: Possible huge clue into unmanged/managed problem"
- Next in thread: cody: "Re: Possible huge clue into unmanged/managed problem"
- Reply: cody: "Re: Possible huge clue into unmanged/managed problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|