Easy Threading Question.

M

Matt Long

I was wondering if any one could help me out with a threading question.

Im developing an app which starts a thread, which in turn starts 4 of its
own threads.

If I call 'sleep' on the initial thread, will this cause all of its children
to sleep also?

Thanks in advance.
 
P

Peter Huang

Hi Matt,

I think the answer is NO. Even the thread A is sleepting the other threads
it creates will not sleep and will continue running.
In windows platform the thread is a kernel object too, the OS allots the
CPU time based on threads, that is to say the OS schedule algorithm will
decide which thread will own CPU time for an assignment unit. Thread A is
sleeping will not impact thread B created in Thread A to sleep too.

Imports System.Threading
Module Module1
Dim bFlag As Boolean = True
Public Sub ThreadProc()
While bFlag
Console.WriteLine(Threading.Thread.CurrentThread.Name + "is
running...")
End While
End Sub
Public Sub StrartupThreadProc()
For i As Integer = 0 To 4
Dim td As New Thread(AddressOf ThreadProc)
td.Name = "Sub Thread" + i.ToString()
td.Start()
Next
Thread.Sleep(5000)
bFlag = False
End Sub
Sub Main()
Dim thread1 As New Thread(AddressOf StrartupThreadProc)
thread1.Name = "First Thread"
thread1.Start()
'wait for thread1 exit
thread1.Join()
End Sub
End Module

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

::P:e:s:c:e:::M:a:r:c:o::

I was wondering if any one could help me out with a threading question.
Im developing an app which starts a thread, which in turn starts 4 of its
own threads.

If I call 'sleep' on the initial thread, will this cause all of its children
to sleep also?

Thanks in advance.
I think the philosophy is wrong ... who get up the thread parent ?
The sleep must not be on it,but the sleep must be called on its children ...

you can check the thread state for wait ....

I Think =o)


--
Ciao

::M:a:r:c:blush::::p:e:s:c:e::
(e-mail address removed)
per contatti PVT elinimare NOSPAM
 
O

One Handed Man \( OHM - Terry Burns \)

I only wish your philosphy were true in real life, my children will stay
awake regardless of my state of conciousness

:)
 
T

The Grim Reaper

LOL!!!

[yawns and tells 3 year old to go to bed..... again....]
____________________________________________________
The Grim Reaper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Multi-Threading 9
Basic Threading question 19
IPC-Remoting: Threading issue in MDI-application 2
VB Threading issues 1
VB.NET and Threading 4
Threading Question - Newbie 3
About threading 2
Threading and Forms 2

Top