_beginthread -- how to terminate a thread from out side of it.

Discussion in 'C Programming' started by liangbowen@hotmail.com, Aug 24, 2005.

  1. Guest

    As i konw, the only way to to terminate a thread started by
    _beginthread() is to user _endthread() (or return) inside the thread.


    now i started a thread(TodoThread), and created a listenning socket
    inside the thread.
    I want to destroy the socket and kill the thread at anytime if there is
    no client connect to it. How?


    void TodoThread(PVOID pvoid){
    //creat a tcp socket
    //then listen
    accept();
    //.....
    }
    , Aug 24, 2005
    #1
    1. Advertising

  2. Jack Klein Guest

    On 23 Aug 2005 23:18:49 -0700, wrote in
    comp.lang.c:

    > As i konw, the only way to to terminate a thread started by
    > _beginthread() is to user _endthread() (or return) inside the thread.
    >
    >
    > now i started a thread(TodoThread), and created a listenning socket
    > inside the thread.
    > I want to destroy the socket and kill the thread at anytime if there is
    > no client connect to it. How?
    >
    >
    > void TodoThread(PVOID pvoid){
    > //creat a tcp socket
    > //then listen
    > accept();
    > //.....
    > }


    We talk about the C language here. It does not have threads or
    sockets. You need to ask in news:comp.os.ms-windows.programmer.win32.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Aug 24, 2005
    #2
    1. Advertising

  3. Guest

    thanks
    , Aug 24, 2005
    #3
  4. You don't really need any complicated API stuff to do this. What I'd do
    is figure out some way of telling the thread to kill itself, when you
    want to kill it. For example set a global variable to some value.
    Obviously, this is non-ideal but its done. [Python used to do this to
    flag exceptions, for example.]

    If this is part of a big program and you're using C++, you should read
    up about the pattern called "Listeners?". [I'm not sure about the name,
    can somebody help me with this?]
    Pramod Subramanyan, Aug 24, 2005
    #4
  5. Flash Gordon Guest

    Pramod Subramanyan wrote:
    > You don't really need any complicated API stuff to do this.


    Do WHAT? Provide CONTEXT, dammit. There have already been complaints
    posted today on top of the complaints posted yesterday on top of...

    So WHY have you not read the group and seen that you need to provide
    context and references to the instructions on how to do it?

    > What I'd do
    > is figure out some way of telling the thread to kill itself,


    If you had bothered to read the group you would also know that threads
    are OFF TOPIC.

    Since you are posting through Google, how could you NOT have seen Jack
    Klein's reply saying this is off topic and redirecting the OP followed
    by the OP thanking him? I know those messages are there because I can
    see them through Google.

    <snip>

    > If this is part of a big program and you're using C++, you should read
    > up about the pattern called "Listeners?". [I'm not sure about the name,
    > can somebody help me with this?]


    Why do you think the OP might be programming in C++ when posting to a C
    news group? C++ is a different language with it's own news group.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Aug 24, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter
    Replies:
    0
    Views:
    493
    Peter
    Aug 28, 2004
  2. Edmond wong
    Replies:
    4
    Views:
    510
    iksrazal
    Mar 29, 2005
  3. Vojta

    Thread - on terminate event

    Vojta, Feb 19, 2006, in forum: Java
    Replies:
    7
    Views:
    6,983
    Stefan Schulz
    Feb 20, 2006
  4. Replies:
    9
    Views:
    694
  5. Replies:
    3
    Views:
    525
    MaRKoV
    Mar 1, 2006
Loading...

Share This Page