[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

killing a thread

Posted on 2005-04-11
16
Medium Priority
?
390 Views
Last Modified: 2008-02-07
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
0
Comment
Question by:xenia27
  • 6
  • 4
  • 3
  • +2
16 Comments
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 800 total points
ID: 13759858
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
 
LVL 5

Expert Comment

by:beryl666
ID: 13759867
>>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
 
LVL 5

Expert Comment

by:beryl666
ID: 13759874
sunnycoder :
wow! very fast. just a blink of eye. then you are here.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
beryl666 earned 1200 total points
ID: 13759892
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 13760357
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
 
LVL 5

Expert Comment

by:beryl666
ID: 13760449
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
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 13760667
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13760785
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13760818
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
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 13760873
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13760955
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 13761256

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
 
LVL 5

Expert Comment

by:beryl666
ID: 13764415
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
 

Author Comment

by:xenia27
ID: 13769738
Question,

I use pthread_create to create threads.  Can I use signal to terminate the threads??
0
 

Author Comment

by:xenia27
ID: 13769817
OK...I got my answer~  Thanks for helping me~~~  ^^
0
 
LVL 5

Expert Comment

by:beryl666
ID: 13780797
Thanks for the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question