{"thread":{"id":"32218","subject":"[PATCH] configure.ac: fix pthreads detection on Mac OS X","startedAt":"2012-11-27T23:28:51Z","lastAt":"2012-11-28T11:38:16Z","messageCount":3,"participants":["Max Horn","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"204058","messageId":"1354058931-88873-1-git-send-email-max@quendi.de","threadId":"32218","inReplyTo":null,"subject":"[PATCH] configure.ac: fix pthreads detection on Mac OS X","fromName":"Max Horn","fromEmail":"max@quendi.de","sentAt":"2012-11-27T23:28:51Z","receivedAt":"2012-11-27T23:28:51Z","isPatch":true,"sender":{"key":"max@quendi.de","avatar":"https://avatars.githubusercontent.com/u/241512?v=4"},"body":"The configure script checks whether certain flags are required to use\npthreads. But it did not consider that *none* might be needed (as is the\ncase on Mac OS X). This lead to configure adding \"-mt\" to the list of\nflags (which does nothing on OS X except producing a warning). This in\nturn triggered a compiler warning on every single file.\n\nTo solve this, we now first check if pthreads work without extra flags.\nThis means the check is now order dependant, hence a comment is added\nexplaining this, and the reasons for it.\n\nNote that it might be possible to write an order independent test, but\nit does not seem worth the extra effort required for implementing and\ntesting such a solution, when this simple solution exists and works.\n\nSigned-off-by: Max Horn <max@quendi.de>\n---\n\nThis is actually a revised version from my patch\n \"Change configure to check if pthreads are usable without any extra flags\"\nfrom July. I simply had forgotten all about it :-(.\n\nChers,\nMax\n\n configure.ac | 12 +++++++++++-\n 1 file changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/configure.ac b/configure.ac\nindex ad215cc..41ac9a5 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -1021,7 +1021,17 @@ if test -n \"$USER_NOPTHREAD\"; then\n # -D_REENTRANT' or some such.\n elif test -z \"$PTHREAD_CFLAGS\"; then\n   threads_found=no\n-  for opt in -mt -pthread -lpthread; do\n+  # Attempt to compile and link some code using pthreads to determine\n+  # required linker flags. The order is somewhat important here: We\n+  # first try it without any extra flags, to catch systems where\n+  # pthreads are part of the C library, then go on testing various other\n+  # flags. We do so to avoid false positives. For example, on Mac OS X\n+  # pthreads are part of the C library; moreover, the compiler allows us\n+  # to add \"-mt\" to the CFLAGS (although it will do nothing except\n+  # trigger a warning about an unused flag). Hence if we checked for\n+  # \"-mt\" before \"\" we would end up picking it. But unfortunately this\n+  # would then trigger compiler warnings on every single file we compile.\n+  for opt in \"\" -mt -pthread -lpthread; do\n      old_CFLAGS=\"$CFLAGS\"\n      CFLAGS=\"$opt $CFLAGS\"\n      AC_MSG_CHECKING([for POSIX Threads with '$opt'])\n-- \n1.8.0.393.gcc9701d\n"},{"id":"204135","messageId":"7vlidmi65n.fsf@alter.siamese.dyndns.org","threadId":"32218","inReplyTo":"1354058931-88873-1-git-send-email-max@quendi.de","subject":"Re: [PATCH] configure.ac: fix pthreads detection on Mac OS X","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-28T06:38:12Z","receivedAt":"2012-11-28T06:38:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Max Horn <max@quendi.de> writes:\n\n> The configure script checks whether certain flags are required to use\n> pthreads. But it did not consider that *none* might be needed (as is the\n> case on Mac OS X). This lead to configure adding \"-mt\" to the list of\n> flags (which does nothing on OS X except producing a warning). This in\n> turn triggered a compiler warning on every single file.\n>\n> To solve this, we now first check if pthreads work without extra flags.\n> This means the check is now order dependant, hence a comment is added\n> explaining this, and the reasons for it.\n>\n> Note that it might be possible to write an order independent test, but\n> it does not seem worth the extra effort required for implementing and\n> testing such a solution, when this simple solution exists and works.\n>\n> Signed-off-by: Max Horn <max@quendi.de>\n> ---\n>\n> This is actually a revised version from my patch\n>  \"Change configure to check if pthreads are usable without any extra flags\"\n> from July. I simply had forgotten all about it :-(.\n\nWill queue, but we would need wider testing to avoid \"compiles well\nwithout an option but fails to link\" issues similar to cea13a8\n(Improve test for pthreads flag, 2011-03-28) on other people's\nplatforms (I know you tested on Mac OS X and over there it compiles\nand links well---I am worried about others).\n\nThanks.\n\n> Chers,\n> Max\n>\n>  configure.ac | 12 +++++++++++-\n>  1 file changed, 11 insertions(+), 1 deletion(-)\n>\n> diff --git a/configure.ac b/configure.ac\n> index ad215cc..41ac9a5 100644\n> --- a/configure.ac\n> +++ b/configure.ac\n> @@ -1021,7 +1021,17 @@ if test -n \"$USER_NOPTHREAD\"; then\n>  # -D_REENTRANT' or some such.\n>  elif test -z \"$PTHREAD_CFLAGS\"; then\n>    threads_found=no\n> -  for opt in -mt -pthread -lpthread; do\n> +  # Attempt to compile and link some code using pthreads to determine\n> +  # required linker flags. The order is somewhat important here: We\n> +  # first try it without any extra flags, to catch systems where\n> +  # pthreads are part of the C library, then go on testing various other\n> +  # flags. We do so to avoid false positives. For example, on Mac OS X\n> +  # pthreads are part of the C library; moreover, the compiler allows us\n> +  # to add \"-mt\" to the CFLAGS (although it will do nothing except\n> +  # trigger a warning about an unused flag). Hence if we checked for\n> +  # \"-mt\" before \"\" we would end up picking it. But unfortunately this\n> +  # would then trigger compiler warnings on every single file we compile.\n> +  for opt in \"\" -mt -pthread -lpthread; do\n>       old_CFLAGS=\"$CFLAGS\"\n>       CFLAGS=\"$opt $CFLAGS\"\n>       AC_MSG_CHECKING([for POSIX Threads with '$opt'])\n"},{"id":"204154","messageId":"316765B5-705F-450D-8191-A29D5AC61E32@quendi.de","threadId":"32218","inReplyTo":"7vlidmi65n.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] configure.ac: fix pthreads detection on Mac OS X","fromName":"Max Horn","fromEmail":"max@quendi.de","sentAt":"2012-11-28T11:38:16Z","receivedAt":"2012-11-28T11:38:16Z","isPatch":true,"sender":{"key":"max@quendi.de","avatar":"https://avatars.githubusercontent.com/u/241512?v=4"},"body":"\nOn 28.11.2012, at 07:38, Junio C Hamano wrote:\n\n> Max Horn <max@quendi.de> writes:\n> \n>> The configure script checks whether certain flags are required to use\n>> pthreads. But it did not consider that *none* might be needed (as is the\n>> case on Mac OS X). This lead to configure adding \"-mt\" to the list of\n>> flags (which does nothing on OS X except producing a warning). This in\n>> turn triggered a compiler warning on every single file.\n>> \n>> To solve this, we now first check if pthreads work without extra flags.\n>> This means the check is now order dependant, hence a comment is added\n>> explaining this, and the reasons for it.\n>> \n>> Note that it might be possible to write an order independent test, but\n>> it does not seem worth the extra effort required for implementing and\n>> testing such a solution, when this simple solution exists and works.\n>> \n>> Signed-off-by: Max Horn <max@quendi.de>\n>> ---\n>> \n>> This is actually a revised version from my patch\n>> \"Change configure to check if pthreads are usable without any extra flags\"\n>> from July. I simply had forgotten all about it :-(.\n> \n> Will queue,\n\nOK\n\n> but we would need wider testing to avoid \"compiles well\n> without an option but fails to link\" issues similar to cea13a8\n> (Improve test for pthreads flag, 2011-03-28) on other people's\n> platforms (I know you tested on Mac OS X and over there it compiles\n> and links well---I am worried about others).\n\nSure, understood. Though note that the test in question performs a compile & link test. So I have a hard time to see how this could break something. Then again, I dabbled in portable code long enough to never say never ;-).\n\nBTW, is there such a thing as a build farm for git which automatically compiles and runs tests for pu / next / main, across a variety of platforms? Or does it all rely on devs test building everything regularly?\n\n\nCheers,\nMax"}]}