Re: pthread_cancel / sleep change in behaviour

2015-09-04 Thread Konstantin Belousov
On Fri, Sep 04, 2015 at 04:35:24PM +0800, Erich Dollansky wrote:
> Hi,.
> 
> On Fri, 4 Sep 2015 11:18:57 +0300
> Konstantin Belousov  wrote:
> 
> > On Fri, Sep 04, 2015 at 08:37:40AM +0800, Erich Dollansky wrote:
> > > On Thu, 3 Sep 2015 13:43:51 +0300
> > > 
> > > and it works there.
> > > 
> > > So, it is just a matter of time until the fix finds its way back to
> > > 10?
> > Yes, should be several days timeframe.
> 
> this sounds perfect.
> > 
> > > 
> > > Of course, I do not ignore the signal now in the application
> > > anymore. The application then works as expected on 10.2 STABLE.
> > Well, the consequence of the bug, which affected you, is that it was
> > allowed for the applications to ignore SIGCANCEL. With the bug fixed,
> > the signal(SIGCANCEL, anything) becomes nop.
> 
> Was it just me being blind or is the documentation on this a bit
> limited?

Documentation on what ? SIGCANCEL is non-standard signal, it is not
documented because this is internal facility for the threading library.
Fiddling with anything without understanding the functionality is not
the best idea.
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-04 Thread Konstantin Belousov
On Fri, Sep 04, 2015 at 08:37:40AM +0800, Erich Dollansky wrote:
> Hi,
> 
> On Thu, 3 Sep 2015 13:43:51 +0300
> Konstantin Belousov  wrote:
> > On Thu, Sep 03, 2015 at 06:33:53PM +0800, Erich Dollansky wrote:
> > > On Thu, 3 Sep 2015 11:19:47 +0300
> > > Konstantin Belousov  wrote:
> > > > On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> > > > > Is this change of behaviour a feature or a bug?
> > > > Provide a minimal example demonstrating the issue.
> > > while preparing the example I found the source of the problem. We
> > > have to block all signals for some reason. The handling for
> > > 
> > > signal (SIGTHR, SIG_IGN);
> > > 
> > > seems to have changed. The moment I remove above's line from the
> > > code, the program works. There is no difference when the programs
> > > runs on machines prior mid November 2014.
> > > 
> > Err, this is a bug, probably both in your program (user code must not
> > twiddle with SIGCANCEL) and in libc. The later, I believe, was fixed
> 
> I just ran the same binary on:
> 
> FreeBSD B85M-HD3-0.alogt.com 11.0-CURRENT FreeBSD 11.0-CURRENT #5
> r287425: Thu Sep  3 21:44:16 WITA 2015
> er...@b85m-hd3-0.alogt.com:/usr/obj/usr/src/sys/B85M-HD3  amd64
> 
> and it works there.
> 
> So, it is just a matter of time until the fix finds its way back to 10?
Yes, should be several days timeframe.

> 
> Of course, I do not ignore the signal now in the application anymore.
> The application then works as expected on 10.2 STABLE.
Well, the consequence of the bug, which affected you, is that it was
allowed for the applications to ignore SIGCANCEL. With the bug fixed,
the signal(SIGCANCEL, anything) becomes nop.
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-04 Thread Erich Dollansky
Hi,.

On Fri, 4 Sep 2015 11:18:57 +0300
Konstantin Belousov  wrote:

> On Fri, Sep 04, 2015 at 08:37:40AM +0800, Erich Dollansky wrote:
> > On Thu, 3 Sep 2015 13:43:51 +0300
> > 
> > and it works there.
> > 
> > So, it is just a matter of time until the fix finds its way back to
> > 10?
> Yes, should be several days timeframe.

this sounds perfect.
> 
> > 
> > Of course, I do not ignore the signal now in the application
> > anymore. The application then works as expected on 10.2 STABLE.
> Well, the consequence of the bug, which affected you, is that it was
> allowed for the applications to ignore SIGCANCEL. With the bug fixed,
> the signal(SIGCANCEL, anything) becomes nop.

Was it just me being blind or is the documentation on this a bit
limited?

Erich
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-03 Thread Konstantin Belousov
On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> Hi,
> 
> I noticed a change in behaviour when calling pthread_cancel for a
> thread which is sleeping using i.e. sleep ().
> 
> How I understand pthread_cancel, it should cancel the thread and call
> the clean up handler soon after its return. Important is that the
> cancelled thread waited on a cancellation point.
> 
> When I started testing our application under error conditions, I found
> problems I could not explain. As the application's target is a
> Raspberry, some tests have been done on a 10.1 on the Raspberry and
> some on a amd64 machine running 10.2 STABLE. The behaviour on the
> Raspberry was as expected but not on the amd64.
> 
> The situation is now that there are always pairs of threads. One thread
> does the work, the other thread just does a sleep() and cancels the
> worker thread at the end. But, when the worker thread finishes its work
> normally, it cancels the sleeping thread and then returns.
> 
> After some time of testing I found out that pthread_cancel calls the
> clean up handler of the sleeping thread only after sleep()'s return
> when running on 10.2 STABLE on amd64 but calls the clean up handler
> soon after cancellation on 10.1 on the Raspberry.
> 
> Is this change of behaviour a feature or a bug?

Provide a minimal example demonstrating the issue.
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-03 Thread Erich Dollansky
Hi,

On Thu, 3 Sep 2015 13:43:51 +0300
Konstantin Belousov  wrote:

> On Thu, Sep 03, 2015 at 06:33:53PM +0800, Erich Dollansky wrote:
> > On Thu, 3 Sep 2015 11:19:47 +0300
> > Konstantin Belousov  wrote:
> > 
> > > On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> > > > 
> > > > Is this change of behaviour a feature or a bug?
> > > 
> > > Provide a minimal example demonstrating the issue.
> > 
> > while preparing the example I found the source of the problem. We
> > have to block all signals for some reason. The handling for
> > 
> > signal (SIGTHR, SIG_IGN);
> > 
> > seems to have changed. The moment I remove above's line from the
> > code, the program works. There is no difference when the programs
> > runs on machines prior mid November 2014.
> > 
> Err, this is a bug, probably both in your program (user code must not
> twiddle with SIGCANCEL) and in libc. The later, I believe, was fixed

I did not know of this. I simply blocked all. As it worked when I
tested it those days, I forgot about it.

> in the HEAD r287300, which is not yet merged back to stable/10. The
> libthr has a protection disallowing user code manipulating SIGCANCEL,
> but due to the bug in libc signal(3) override the libthr measures.
> 
> Apply the r287300 to your src/ and try your unchanged program with
> updated libc.  But yes, SIGTHR/SIGCANCEL in the program is bug.
> 
I am just updating another machine. It might be already tomorrow when I
will come back to you.

Erich
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-03 Thread Erich Dollansky
Hi,

On Thu, 3 Sep 2015 11:19:47 +0300
Konstantin Belousov  wrote:

> On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> > 
> > Is this change of behaviour a feature or a bug?
> 
> Provide a minimal example demonstrating the issue.

while preparing the example I found the source of the problem. We have
to block all signals for some reason. The handling for

signal (SIGTHR, SIG_IGN);

seems to have changed. The moment I remove above's line from the code,
the program works. There is no difference when the programs runs on
machines prior mid November 2014.

Thanks for your help. Simplifying the program brought me to the
solution. 

Do you want the example?

Erich
> ___
> freebsd-stable@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-stable
> To unsubscribe, send any mail to
> "freebsd-stable-unsubscr...@freebsd.org"

___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-03 Thread Konstantin Belousov
On Thu, Sep 03, 2015 at 06:33:53PM +0800, Erich Dollansky wrote:
> Hi,
> 
> On Thu, 3 Sep 2015 11:19:47 +0300
> Konstantin Belousov  wrote:
> 
> > On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> > > 
> > > Is this change of behaviour a feature or a bug?
> > 
> > Provide a minimal example demonstrating the issue.
> 
> while preparing the example I found the source of the problem. We have
> to block all signals for some reason. The handling for
> 
> signal (SIGTHR, SIG_IGN);
> 
> seems to have changed. The moment I remove above's line from the code,
> the program works. There is no difference when the programs runs on
> machines prior mid November 2014.
> 
Err, this is a bug, probably both in your program (user code must not
twiddle with SIGCANCEL) and in libc. The later, I believe, was fixed in
the HEAD r287300, which is not yet merged back to stable/10. The libthr
has a protection disallowing user code manipulating SIGCANCEL, but due
to the bug in libc signal(3) override the libthr measures.

Apply the r287300 to your src/ and try your unchanged program with updated
libc.  But yes, SIGTHR/SIGCANCEL in the program is bug.

> Thanks for your help. Simplifying the program brought me to the
> solution. 
> 
> Do you want the example?
> 
> Erich
> > ___
> > freebsd-stable@freebsd.org mailing list
> > https://lists.freebsd.org/mailman/listinfo/freebsd-stable
> > To unsubscribe, send any mail to
> > "freebsd-stable-unsubscr...@freebsd.org"
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


Re: pthread_cancel / sleep change in behaviour

2015-09-03 Thread Erich Dollansky
Hi,

On Thu, 3 Sep 2015 13:43:51 +0300
Konstantin Belousov  wrote:
> On Thu, Sep 03, 2015 at 06:33:53PM +0800, Erich Dollansky wrote:
> > On Thu, 3 Sep 2015 11:19:47 +0300
> > Konstantin Belousov  wrote:
> > > On Thu, Sep 03, 2015 at 08:00:47AM +0800, Erich Dollansky wrote:
> > > > Is this change of behaviour a feature or a bug?
> > > Provide a minimal example demonstrating the issue.
> > while preparing the example I found the source of the problem. We
> > have to block all signals for some reason. The handling for
> > 
> > signal (SIGTHR, SIG_IGN);
> > 
> > seems to have changed. The moment I remove above's line from the
> > code, the program works. There is no difference when the programs
> > runs on machines prior mid November 2014.
> > 
> Err, this is a bug, probably both in your program (user code must not
> twiddle with SIGCANCEL) and in libc. The later, I believe, was fixed

I just ran the same binary on:

FreeBSD B85M-HD3-0.alogt.com 11.0-CURRENT FreeBSD 11.0-CURRENT #5
r287425: Thu Sep  3 21:44:16 WITA 2015
er...@b85m-hd3-0.alogt.com:/usr/obj/usr/src/sys/B85M-HD3  amd64

and it works there.

So, it is just a matter of time until the fix finds its way back to 10?

Of course, I do not ignore the signal now in the application anymore.
The application then works as expected on 10.2 STABLE.

Thanks for your work and also thanks for your help.

Erich
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"


pthread_cancel / sleep change in behaviour

2015-09-02 Thread Erich Dollansky
Hi,

I noticed a change in behaviour when calling pthread_cancel for a
thread which is sleeping using i.e. sleep ().

How I understand pthread_cancel, it should cancel the thread and call
the clean up handler soon after its return. Important is that the
cancelled thread waited on a cancellation point.

When I started testing our application under error conditions, I found
problems I could not explain. As the application's target is a
Raspberry, some tests have been done on a 10.1 on the Raspberry and
some on a amd64 machine running 10.2 STABLE. The behaviour on the
Raspberry was as expected but not on the amd64.

The situation is now that there are always pairs of threads. One thread
does the work, the other thread just does a sleep() and cancels the
worker thread at the end. But, when the worker thread finishes its work
normally, it cancels the sleeping thread and then returns.

After some time of testing I found out that pthread_cancel calls the
clean up handler of the sleeping thread only after sleep()'s return
when running on 10.2 STABLE on amd64 but calls the clean up handler
soon after cancellation on 10.1 on the Raspberry.

Is this change of behaviour a feature or a bug?

Erich
___
freebsd-stable@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"