G
Guest
Hi,
As I understand, if a code section inside a sub called with threadX.Start
is between BeginCriticalRegion - EndCriticalRegion, it should complete (at
least that portion of code, not the whole 'sub'... even if a TreadX.Abort is
used, if this portion of code is running when you call that Abort.
So With this program, I would expect to print :
I'm still standing, yeh yeh yéah
Main thread finished
But only
Main thread finished
appears because thread is aborted although The code between critical region
is running... Why ?
Code:
Sub Main()
Dim myThreadx As New Thread(AddressOf subWithASleep)
myThreadx.Start()
Thread.Sleep(2000) 'For the called thread to have some time to enter that
"begin-critical-region"
myThreadx.Abort()
Console.WriteLine("Main thread finished")
end sub
Public Sub subWithASleep()
Thread.BeginCriticalRegion()
Thread.Sleep(15000) 'waits 15 seconds
Console.Write("I'm still standing, yeh yeh yéah") 'It should show
but it does NOT !
Thread.EndCriticalRegion()
End Sub
As I understand, if a code section inside a sub called with threadX.Start
is between BeginCriticalRegion - EndCriticalRegion, it should complete (at
least that portion of code, not the whole 'sub'... even if a TreadX.Abort is
used, if this portion of code is running when you call that Abort.
So With this program, I would expect to print :
I'm still standing, yeh yeh yéah
Main thread finished
But only
Main thread finished
appears because thread is aborted although The code between critical region
is running... Why ?
Code:
Sub Main()
Dim myThreadx As New Thread(AddressOf subWithASleep)
myThreadx.Start()
Thread.Sleep(2000) 'For the called thread to have some time to enter that
"begin-critical-region"
myThreadx.Abort()
Console.WriteLine("Main thread finished")
end sub
Public Sub subWithASleep()
Thread.BeginCriticalRegion()
Thread.Sleep(15000) 'waits 15 seconds
Console.Write("I'm still standing, yeh yeh yéah") 'It should show
but it does NOT !
Thread.EndCriticalRegion()
End Sub