Link to home
Start Free TrialLog in
Avatar of xenia27
xenia27Flag for Taiwan, Province of China

asked on

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
SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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
sunnycoder :
wow! very fast. just a blink of eye. then you are here.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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
ROTFL .... It sounds like a big conspiracy!!!

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

Before you start using it, make *sure* that you have read this
https://www.experts-exchange.com/questions/21375786/Javascript-Posting-Guidelines-discussion-thread.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
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.
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
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  :)

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.


  ;)

sunnycoder:
>Wish you had checked the help pages
>https://www.experts-exchange.com/help.jsp#hi83
>Before you start using it, make *sure* that you have read this
>https://www.experts-exchange.com/questions/21375786/Javascript-Posting-Guidelines-discussion-thread.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 ?
Avatar of xenia27

ASKER

Question,

I use pthread_create to create threads.  Can I use signal to terminate the threads??
Avatar of xenia27

ASKER

OK...I got my answer~  Thanks for helping me~~~  ^^
Thanks for the points.