Re: [Mingw-w64-public] winpthreads, pthread_setschedparam, and detached threads

2016-06-01 Thread Burkhardt, Glenn B UTAS
It's not clear to me from this explanation why this code should fail:

pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m);

but in winpthreads, for a detached thread, it will.  

> Re: [Mingw-w64-public] winpthreads, pthread_setschedparam, and detached 
> threads
> From: lh mouse - 2016-06-01 03:31:43

> Note that in most cases threads other than the one calling `pthread_detach()` 
> can terminate at anytime. After a call `pthread_detach()`, if the thread 
> terminates, its resources are freed automatically, rendering the `pthread_t` 
> no longer valid. It is impossible to tell whether a `pthread_t` is 
> designating a thread that has terminated. It may even be designating a thread 
> that is different from the one the user expects because thread IDs 
> can be reused.

> By calling `pthread_detach()` on a `pthread_t` you _semantically_ 
> destroy/close it and should not use it any more.

--   
Best regards,
lh_mouse
2016-06-01

-
发件人:"Burkhardt, Glenn BUTAS" 
发送日期:2016-05-31 23:11
收件人:mingw-w64-public@...
抄送:
主题:[Mingw-w64-public] winpthreads, pthread_setschedparam,
and detached threads

The way the winpthreads code is writing, the Windows handle for the thread is 
cleared when the thread is made detached.  That means that the 
pthread_setschedparam() call can't work.  So thread priorities for detached 
threads can only be set once, at thread creation, before the thread is 
detached, or as part of the pthread_create() call.

Is there a reason for this?  For me, it's unexpected behavior.




--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] winpthreads, pthread_setschedparam, and detached threads

2016-06-01 Thread lh mouse
I think it would be a bug in your example. Were it not a bug there would be no 
way for a detached thread to operate itself.

--   
Best regards,
lh_mouse
2016-06-01

-
发件人:"Burkhardt, Glenn BUTAS" 
发送日期:2016-06-01 21:25
收件人:mingw-w64-public@lists.sourceforge.net
抄送:
主题:Re: [Mingw-w64-public] winpthreads, pthread_setschedparam,
 and detached threads

It's not clear to me from this explanation why this code should fail:

pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m);

but in winpthreads, for a detached thread, it will.  

> Re: [Mingw-w64-public] winpthreads, pthread_setschedparam, and detached 
> threads
> From: lh mouse - 2016-06-01 03:31:43

> Note that in most cases threads other than the one calling `pthread_detach()` 
> can terminate at anytime. After a call `pthread_detach()`, if the thread 
> terminates, its resources are freed automatically, rendering the `pthread_t` 
> no longer valid. It is impossible to tell whether a `pthread_t` is 
> designating a thread that has terminated. It may even be designating a thread 
> that is different from the one the user expects because thread IDs 
> can be reused.

> By calling `pthread_detach()` on a `pthread_t` you _semantically_ 
> destroy/close it and should not use it any more.

--   
Best regards,
lh_mouse
2016-06-01

-
发件人:"Burkhardt, Glenn BUTAS" 
发送日期:2016-05-31 23:11
收件人:mingw-w64-public@...
抄送:
主题:[Mingw-w64-public] winpthreads, pthread_setschedparam,
and detached threads

The way the winpthreads code is writing, the Windows handle for the thread is 
cleared when the thread is made detached.  That means that the 
pthread_setschedparam() call can't work.  So thread priorities for detached 
threads can only be set once, at thread creation, before the thread is 
detached, or as part of the pthread_create() call.

Is there a reason for this?  For me, it's unexpected behavior.




--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] winpthreads, pthread_setschedparam, and detached threads

2016-06-01 Thread K. Frank
Hello Lefty!

On Tue, May 31, 2016 at 11:31 PM, lh mouse  wrote:
> Note that in most cases threads other than the one calling `pthread_detach()` 
> can terminate at anytime.
> ...

I would say your description fits the typical use case.

> By calling `pthread_detach()` on a `pthread_t` you _semantically_ 
> destroy/close it and should not use it any more.

Well, maybe.  I certainly don't find anything in the pthread standard that
justifies this semantic interpretation (nor that contradicts it).  I do expect
that many people look at it the way you do.

One can certainly imagine a use case where "using" a detached thread (and
calling pthread_setschedparam() on it) would make sense.  Detached threads
still respect synchronization objects (e.g., mutexes and condition variable, but
not pthread_join).  So maybe you have a detached thread servicing some sort
of queue (controlled by a condition variable) and you want to throttle it by
changing its priority, so you want to call pthread_setschedparam() on it.

Of course, you can easily work around this issue by not detaching the thread.

>
> Best regards,
> lh_mouse
> 2016-06-01


Happy Hacking!


> 发件人:"Burkhardt, Glenn BUTAS" 
> ...
> 主题:[Mingw-w64-public] winpthreads, pthread_setschedparam,
> and detached threads
>
> The way the winpthreads code is writing, the Windows handle for the thread is 
> cleared when the thread is made detached.  That means that the 
> pthread_setschedparam() call can't work.  So thread priorities for detached 
> threads can only be set once, at thread creation, before the thread is 
> detached, or as part of the pthread_create() call.
> ...

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public