• C

killing a thread

Hi,

How can I kill a thread which is create by pthread_create function???

What I do is I create two threads by "pthread_create", server_thread and client_thread.
And server_thread runs first, and then, client_thread will detect whether there is a socket connection, if yes, I would like to terminate server_thread.

I try to use "kill(server_thread, 1)" and it seems like server_thread is still running...and I try "pthread_kill(server_thread, 9)", it seems like my program is terminated...any suggestion how can I do this???


Xenia
xenia27Asked:
Who is Participating?
 
sunnycoderCommented:
I am sure I helped someone solve similar problem before, just cant recollect it ...

What you can try is setting a signal handler and a signal mask and using something like SIGUSR instead of kill. You can exit the thread gracefully by setting a flag in the signal handler.

from the man page:::

Recall that signal masks are set on a per-thread basis, but signal actions and signal handlers, as set with sigaction(2), are shared between all threads.
0
 
beryl666Commented:
>>I try to use "kill(server_thread, 1)" and it seems like server_thread is still running
That's mean you didn't successfully kill it.

instead of using pthread_kill(), try kill()
refer:
http://www.mkssoftware.com/docs/man3/kill.3.asp
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
beryl666Commented:
sunnycoder :
wow! very fast. just a blink of eye. then you are here.
0
 
PaulCaswellCommented:
Beryl,

>>wow! very fast. just a blink of eye. then you are here.
They (the mods and page editors and a chosen few others) have some script that watches for questions being posted and e-mails them. They wont release it and I understand why not.

I remember some months back sunny posting the script here for Kent to pick up. I didnt realise what it was quickly enough and sunny deleted it before I got a copy. I live in hope that one day Ill get get a copy. I am sure I will guard it as closely as they do.

Paul
0
 
beryl666Commented:
Paul:
no wonder la. every time i try to answer question. sunnycoder will always here. but because of that script i think it make the EE has the fastest reply.

to sunnycoder:
Don't be so stingy. why don't you make a competition, for example those who can reach some level of points that he/she can get the script?
nice suggestion right?

Beryl.
0
 
PaulCaswellCommented:
Beryl,

Try not to have a go at sunny. He knows what he's doing. Sometimes he comes in too quickly but imo not too often. We all get enough lookin to get some decent points. There must be a balance between quick replies that get customers/askers coming back and too many replies which just end up confusing things. If too many people get the script there would not be the flexibility available to adjust EE to maximal advantage to all.

The tool instills power and power corrupts. I'd rather its only in the hands of the accountable.

The competition is already there. Get enough points and act responsably and there's a good chance you'll be trusted enough to get the tool.

Paul
0
 
sunnycoderCommented:
ROTFL .... It sounds like a big conspiracy!!!

Wish you had checked the help pages
http://www.experts-exchange.com/help.jsp#hi83

Before you start using it, make *sure* that you have read this
http://www.experts-exchange.com/Community_Support/Expert_Input/Q_21375786.html
Though it has been posted for JS TA, same rules apply site wide.

Paul,

>I remember some months back sunny posting the script here for Kent to pick up. I didnt realise what it was quickly enough and sunny
>deleted it before I got a copy. I live in hope that one day Ill get get a copy. I am sure I will guard it as closely as they do.
When was that? Can you give me a link? It would be fun to see it at least once ;-)

Cheers!
sunnycoder
0
 
sunnycoderCommented:
Just to dispell another myth:
Points are *never* a criteria for judging an expert. There are Page Editors who do not have a huge pile of points behind them and there are experts who have huge number of points but do not have that kind of respect in the eyes of their peers (or the admins). Points get us into Top 15 which looks good on us, they get us certs but thats all. It is always collaboration spirit, behavior, expertise, follow-up etc which count. In short, everything except points :-)

That is the reason I recommend reading that expert input thread before you start using QP.
0
 
PaulCaswellCommented:
Sunny,

No suggestion of conspiracy intended! It felt right that page editors should have more power than us, you are expected to do so much more.

I thought it was all carefully hidden. Good links too. Thanks for the clearup.

>>When was that?...
I really dont  remember! I had been on EE for just a few weeks and it may even not have been you passing the script. I just remember the same question being asked and a bit of hushing up of the answer being done.

Paul
0
 
sunnycoderCommented:
ok .... that was Kent asking me the same question, I had posted the same link and then sort of pseudo-whined that I had commited a big mistake by sharing the link with competition :-)
Nothing was removed from that question and I think it should still be in PAQ database.

>It felt right that page editors should have more power than us, you are expected to do so much more.
Page Editors (and mods & admins) do have additional set of tools and a slightly different view of the site that helps us perform our PE/Mod/Admin related duties. But as far as answering questions is concerned, we are all on the same plane ... fair and healthy competition  :)
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Man, oh, man....

Even when I keep my head down my I get shot at.  :)

This "having an evil twin" isn't all that it's cracked up to be.


  ;)

0
 
beryl666Commented:
sunnycoder:
>Wish you had checked the help pages
>http://www.experts-exchange.com/help.jsp#hi83
>Before you start using it, make *sure* that you have read this
>http://www.experts-exchange.com/Community_Support/Expert_Input/Q_21375786.html
>Though it has been posted for JS TA, same rules apply site wide.
may i know what is the link for?
what is ROTFL ?
0
 
xenia27Author Commented:
Question,

I use pthread_create to create threads.  Can I use signal to terminate the threads??
0
 
xenia27Author Commented:
OK...I got my answer~  Thanks for helping me~~~  ^^
0
 
beryl666Commented:
Thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.