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

L

liangbowen

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();
//.....
}
 
J

Jack Klein

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
 
P

Pramod Subramanyan

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?]
 
F

Flash Gordon

Pramod said:
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.

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top