How do I put to sleep a thread other than the current one.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Rilling

    How do I put to sleep a thread other than the current one.

    How do I put to sleep a thread other than the current one?

    I want to put another thread to sleep to the specified number of
    milliseconds but the Sleep method seems to only work for the current thread
    while the Suspend method has no parameters to specify a duration.


  • Wiktor Zychla

    #2
    Re: How do I put to sleep a thread other than the current one.

    > I want to put another thread to sleep to the specified number of[color=blue]
    > milliseconds but the Sleep method seems to only work for the current[/color]
    thread[color=blue]
    > while the Suspend method has no parameters to specify a duration.[/color]

    I am afraid that this is not possible at all. for the thread to sleep it
    must be active at the moment you invoke the sleep function (otherwise it is
    senseless because the thead IS sleeping!).

    what you want to do is not to call Sleep for the other thread but rather to
    block its execution for some time. to accomplish that you should use any
    object that can synchronize threads, for example Mutexes.

    Regards,
    Wiktor Zychla


    Comment

    • Rene

      #3
      Re: How do I put to sleep a thread other than the current one.

      > I am afraid that this is not possible at all. for the thread to sleep it[color=blue]
      > must be active at the moment you invoke the sleep function (otherwise it[/color]
      is[color=blue]
      > senseless because the thead IS sleeping!).[/color]

      What if I have a dual processor? Can't processor 1 and 2 be running a
      different thread at the same time?



      Comment

      • Dave

        #4
        Re: How do I put to sleep a thread other than the current one.

        "Rene" <nospam@nospam. com> wrote in message
        news:O52qOG0fDH A.3248@tk2msftn gp13.phx.gbl...[color=blue][color=green]
        > > I am afraid that this is not possible at all. for the thread to sleep it
        > > must be active at the moment you invoke the sleep function (otherwise it[/color]
        > is[color=green]
        > > senseless because the thead IS sleeping!).[/color]
        >
        > What if I have a dual processor? Can't processor 1 and 2 be running a
        > different thread at the same time?
        >[/color]
        Sure, but you still need to use the correct synchronization mechanism. In
        almost all cases you should use a sync object, e.g. ManualResetEven t, and
        the thread blocks on that object until some other thread sets the object to
        the signalled state, rather then directly Suspend/Resume a thread.


        Comment

        Working...