This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Disable sched_get_priority_min/max if Python is compiled without threads
Type: compile error Stage: resolved
Components: Extension Modules Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: nadeem.vawda, neologix, python-dev, rpointel, vstinner
Priority: normal Keywords: patch

Created on 2011-08-31 18:03 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sched_get_priority.diff neologix, 2011-09-04 11:51 review
Messages (9)
msg143270 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-08-31 18:03
If Pyton is configured without thread support (--without-threads), the compilation fails on OpenBSD :

$ make
[...]
./Modules/posixmodule.c:4582: undefined reference to `sched_get_priority_min'
libpython3.3m.a(posixmodule.o)(.text+0x430b): In function `posix_sched_get_priority_max':
./Modules/posixmodule.c:4565: undefined reference to `sched_get_priority_max'
collect2: ld returned 1 exit status
*** Error code 1

I didn't try on Linux, but I suppose that the issue is not specific to OpenBSD.
msg143276 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2011-08-31 18:45
I haven't been able to reproduce this on Linux (2.6.38; Ubuntu 11.04).
Some searching around seems to suggest that OpenBSD doesn't provide
those functions (or didn't until recently). Modules/posixmodule.c and
configure.in seem to assume that these functions are available if
sched.h exists. Adding an explicit check for them should solve the
problem.
msg143277 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2011-08-31 18:48
There's no reason to disable sched_get_priority_(min|max) when Python is built without threads: those libraries control the scheduling policy, and should be available even without pthread.
However, it's really likely that pthread has its own implementation (especially since OpenBSD's threads are implemented in user-space), and it seems that OpenBSD sched_get_priority() is only defined for threads:
http://www.openbsd.org/cgi-bin/man.cgi?query=sched_get_priority_max&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
"""
This implementation does not support process scheduling.
"""

For example, the following snippet builds correctly on Linux:

"""
#include <sched.h>


int main(int argc, char *argv[])
{
    int (*fp)(int) = sched_get_priority_max;

    return 0;
}
"""

So this should be skipped only on OpenBSD, or we should add some checks to the configure script.
msg143361 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-09-01 22:06
> For example, the following snippet builds correctly on Linux

It builds correctly with -pthread or -lpthread, but it fails to build without these options.

sched_get_priority_max() and sched_get_priority_min() come from libpthread on OpenBSD, whereas Python only checks for "#ifdef HAVE_SCHED_H".
msg143381 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2011-09-02 05:51
> It builds correctly with -pthread or -lpthread, but it fails to build without these options.
>

Not on Linux: this is specific to OpenBSD.

> sched_get_priority_max() and sched_get_priority_min() come from libpthread on OpenBSD, whereas Python only checks for "#ifdef HAVE_SCHED_H".
>

That's exactly what I said in my previous message ;-)
I'll post a patch later.
msg143388 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-09-02 08:11
>> It builds correctly with -pthread or -lpthread, but it fails to build without these options.
>>
>
> Not on Linux: this is specific to OpenBSD.

Oh, I forgot to specify: yes, I tested on OpenBSD (5.0).

>> sched_get_priority_max() and sched_get_priority_min() come from libpthread on OpenBSD, whereas Python only checks for "#ifdef HAVE_SCHED_H".
>>
>
> That's exactly what I said in my previous message ;-)
> I'll post a patch later.

Yep, it's just that I have the confirmation with my tests.
msg143494 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2011-09-04 11:51
Here's a patch adding a configure-time check. Since the functions are
checked without being linked explicitely with pthread, it should do
the trick (I couldn't test it on OpenBSD though).
I also added a skipTest to test_posix.test_sched_priority().
msg143497 - (view) Author: Remi Pointel (rpointel) * Date: 2011-09-04 13:13
Hi,

it seems to solve the problem (tested on OpenBSD 4.9 and OpenBSD-current).

* test_posix.py on OpenBSD 4.9:
[...]
Ran 79 tests in 0.508s
OK (skipped=35)

* test_posix.py on OpenBSD-current:
it continues to segfault, but I have opened an other ticket for this problem (issue 12852).

Thanks a lot,

Remi.
msg143633 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-09-06 17:02
New changeset 5c8b6e03ebfe by Charles-François Natali in branch 'default':
Issue #12871: sched_get_priority_(min|max) might not be defined even though
http://hg.python.org/cpython/rev/5c8b6e03ebfe
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57080
2011-09-06 18:29:54neologixsetstatus: open -> closed
type: compile error
resolution: fixed
stage: resolved
2011-09-06 17:02:10python-devsetnosy: + python-dev
messages: + msg143633
2011-09-04 13:13:26rpointelsetmessages: + msg143497
2011-09-04 11:51:46neologixsetfiles: + sched_get_priority.diff
keywords: + patch
messages: + msg143494

title: Disable sched_get_priority_min/max if Python is compiled without threads -> Disable sched_get_priority_min/max if Python is compiled without threads
2011-09-02 08:11:14vstinnersetmessages: + msg143388
title: Disable sched_get_priority_min/max if Python is compiled without threads -> Disable sched_get_priority_min/max if Python is compiled without threads
2011-09-02 05:51:15neologixsetmessages: + msg143381
title: Disable sched_get_priority_min/max on OpenBSD if Python is compiled without threads -> Disable sched_get_priority_min/max if Python is compiled without threads
2011-09-01 22:06:33vstinnersettitle: Disable sched_get_priority_min/max if Python is compiled without threads -> Disable sched_get_priority_min/max on OpenBSD if Python is compiled without threads
2011-09-01 22:06:09vstinnersetmessages: + msg143361
2011-08-31 18:48:49neologixsetnosy: + neologix
messages: + msg143277
2011-08-31 18:45:13nadeem.vawdasetnosy: + nadeem.vawda
messages: + msg143276
2011-08-31 18:03:40vstinnercreate