By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

Easy Threading Question.

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.N ame + "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.

Nov 20 '05 #2

P: n/a
> 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:o:::P:e:s:c:e::
it***************@hotmail.com
per contatti PVT elinimare NOSPAM
Nov 20 '05 #3

P: n/a
No

/claes

"Matt Long" <So******@NOSPAM.Diskcovery.com.au> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 20 '05 #4

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

:-)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"::P:e:s:c:e:::M:a:r:c:o::" <it***************@hotmail.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
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:o:::P:e:s:c:e::
it***************@hotmail.com
per contatti PVT elinimare NOSPAM

Nov 20 '05 #5

P: n/a
LOL!!!

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

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:Of*************@tk2msftngp13.phx.gbl...
I only wish your philosphy were true in real life, my children will stay
awake regardless of my state of conciousness

:-)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"::P:e:s:c:e:::M:a:r:c:o::" <it***************@hotmail.com> wrote in message news:u7**************@TK2MSFTNGP09.phx.gbl...
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:o:::P:e:s:c:e::
it***************@hotmail.com
per contatti PVT elinimare NOSPAM


Nov 20 '05 #6

P: n/a
Thankyou Peter, that was a great help.

""Peter Huang"" wrote:
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.N ame + "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.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.