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

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

  1. liangbowen

    liangbowen 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
    liangbowen, Aug 24, 2005
    1. Advertisements

  2. liangbowen

    Jack Klein Guest

    We talk about the C language here. It does not have threads or
    sockets. You need to ask in
    Jack Klein, Aug 24, 2005
    1. Advertisements

  3. liangbowen

    liangbowen Guest

    liangbowen, Aug 24, 2005
  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
  5. liangbowen

    Flash Gordon Guest

    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?
    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.

    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, Aug 24, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.