2013/5/31 Xin Wang <[email protected]>

>
>
>
> 2013/5/31 Nala Ginrut <[email protected]>
>
>> On Fri, 2013-05-31 at 14:24 +0800, Xin Wang wrote:
>>
>> >
>> >
>> > Thank you for pointing out this.
>> >
>> >
>> > After some more search, I found that pthread has function pthread_kill
>> > [1], which can be used to send signal to specific thread.
>> >
>> >
>> > No sure if it can be used to implement similar behaviour.
>> >
>> >
>> > [1]
>> >
>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html
>>
>>
>> At least in Linux, pthread_kill may effect the whole process:
>> ----------------------------cut----------------------------------
>> Signal  dispositions  are  process-wide: if a signal handler is
>> installed, the handler will be invoked in the thread thread,
>> but if the disposition of the signal is "stop", "continue", or
>> "terminate", this action will affect the whole process.
>> ----------------------------end----------------------------------
>>
>> The real solution for your purpose is green-thread IMO.
>>
>>
> I see.
>
> But I think it is still doable, although not elegant.
>
> We can establish a signal handler to exit specific thread instead of a
> global terminate disposition, and then in thread pthread_sigmask() can be
> used to block that signal temporarily, before calling out-guard part of
> dynamic-wind.
>
> Some sample C code: https://gist.github.com/dram/5683646
>
>
I think I have found a much simpler method.

pthread_cancel request can be blocked by pthread_setcancelstate.

See code for more info: https://gist.github.com/dram/5684164


>
>> >
>> >
>> >         > Regards,
>> >         > Xin Wang
>> >
>> >
>> >
>> >
>>
>>
>>
>

Reply via email to