Skip Menu |

This queue is for tickets about the Perl-Dist-Strawberry CPAN distribution.

Report information
The Basics
Id: 87906
Status: resolved
Priority: 0/
Queue: Perl-Dist-Strawberry

People
Owner: Nobody in particular
Requestors: david.jacobowitz [...] gmail.com
Cc: sisyphus1 [...] optusnet.com.au
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: pthreads header problem and Inline::C
Date: Fri, 16 Aug 2013 13:58:57 -0700
To: bug-perl-dist-strawberry [...] rt.cpan.org
From: David Jacobowitz <david.jacobowitz [...] gmail.com>
I've been trying to build a project that uses Strawberry Perl, Inline::C and pthreads and ran into some problems compiling on my system on Win32. (It works fine in Ubuntu) In particular, it looks like some header file somewhere (I have still to determine which despite grepping through all the obvious places) does something along the lines of: #define PTHREAD_CREATE_JOINABLE 0 but in the pthreads.h in the distribution, there is an enum like this: enum { PTHREAD_CREATE_JOINABLE = 0, ... } Well, when the preprocessor runs it replaces the macro with 0, and you get enum { 0 = 0, ... } on which the compiler of course barfs. I initially tried solving the problem by putting undef PTHREAD_CREATE_JOINABLE before I include <pthread.h>. That fixed the compilation but using threads resulted in segaults. So now I have #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE This makes the enum in pthread.h happy and anyone expecting the macro gets the enum value, which is the same and is also happy. So far all is working, but who know if this is a correct solution. I spent a long time not able to figure out the source of these segfaults. Bug is present in at least 5.16 and 5.18 that I tried. perl --version: This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x86-multi-thread OS is Windows 7 32b. gnuwin32 "uname -a" reports: windows32 DAVIDJ-LT0362 2.6.1 7601 i686-pc Intel unknown MinG I have attached a working and non-working example perl scripts. fail.plwill not compile. work.pl will print messages until stopped. Regards, Dave Jacobowitz PS A few feature requests: - package a gdb with SP - offer an SP built with debugging enabled - make it so gdb can debug the dlls created by the Inline modules. Adding -g to Inline => Config => CCFLAGS doesn't do it.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

I am afraid that trouble is in perl/lib/CORE/threads.h section:

#ifndef PTHREAD_CREATE_JOINABLE
Show quoted text
#  ifdef OLD_PTHREAD_CREATE_JOINABLE
#    define PTHREAD_CREATE_JOINABLE OLD_PTHREAD_CREATE_JOINABLE
#  else
#    define PTHREAD_CREATE_JOINABLE 0 /* Panic?  No, guess. */
#  endif
#endif

If my guess is correct it is more related to perl core than strawberry perl specifically

--
kmx

I have put into Cc: Sisyphus - the author of Inline::C + AFAIK occasional Strawberry Perl user - he might have a better comment on this issue.
Subject: Re: [rt.cpan.org #87906] pthreads header problem and Inline::C
Date: Mon, 25 Nov 2013 11:38:34 +1100
To: <bug-Perl-Dist-Strawberry [...] rt.cpan.org>, <david.jacobowitz [...] gmail.com>
From: <sisyphus1 [...] optusnet.com.au>
Show quoted text
-----Original Message----- From: kmx via RT Sent: Monday, November 25, 2013 9:19 AM To: david.jacobowitz@gmail.com Cc: sisyphus1@optusnet.com.au Subject: [rt.cpan.org #87906] pthreads header problem and Inline::C
> <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > > > I have put into Cc: Sisyphus - the author of Inline::C + AFAIK occasional > Strawberry Perl user - he might have a better comment on this issue.
I don't have a lot to offer here. I'm quite sure that kmx has nailed the source of the problem, and one has only to "#include <pthread.h>" in any Inline::C script (on Windows) to strike the error that David encountered. I don't have much experience with pthreads, but I regularly build PDL with pthreads on Windows, and it works fine. In the PDL source, they simply do (as David tried): #ifdef PTHREAD_CREATE_JOINABLE #undef PTHREAD_CREATE_JOINABLE #endif #include <pthread.h> and the comments accompanying that code explain that's done simply to work around the problem with CORE/lib/thread.h on Windows. (I don't know why that hasn't worked for David .... something from elsewhere in his code perhaps ?) The comments also explain that this workaround is only needed for Windows - the *nix implementations of pthread.h generally use macros instead of enum to set PTHREAD_CREATE_JOINABLE to 0, so there's no such problem there. Thanks for cc'ing, kmx. As an afterthought, it seems odd that the "#undef PTHREAD_CREATE_JOINABLE" failed, but "#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE" worked. In this simplistic Inline::C script it makes no difference (apart from a re-definition warning during compilation) which construct you use: ############################# use warnings; use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; #undef PTHREAD_CREATE_JOINABLE /* #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE */ #include <pthread.h> void foo() { printf("%d\n", PTHREAD_CREATE_JOINABLE); } EOC foo(); ############################# Cheers, Rob
On Sun Nov 24 19:39:14 2013, sisyphus1@optusnet.com.au wrote: Show quoted text
> > > -----Original Message----- > From: kmx via RT > Sent: Monday, November 25, 2013 9:19 AM > To: david.jacobowitz@gmail.com > Cc: sisyphus1@optusnet.com.au > Subject: [rt.cpan.org #87906] pthreads header problem and Inline::C >
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > > > > > I have put into Cc: Sisyphus - the author of Inline::C + AFAIK occasional > > Strawberry Perl user - he might have a better comment on this issue.
Sorry - when I wrote my reply I didn't realise that Dave had provided sample scripts. The "works.pl" works fine for me, as expected. I've also grabbed "fails.pl" and inserted the "#undef PTHREAD_CREATE_JOINABLE" immediately before the inclusion of pthread.h. That script (ie "fails.h") then runs fine for me ... no segfaults at all !! Admittedly I don't have the exact same version of Strawberry as Dave was running. I tried on Strawberry Perls (portable) 5.16.0, and 5.18.0. I also tried it on a mingw.org compiler-built 5.16.0 - again no problems. Seems odd. kmx, did you try running "fails.h" (amended as per above) on any of your Strawberry Perl installations ? Cheers, Rob
CC: Sisyphus <sisyphus1 [...] optusnet.com.au>
Subject: Re: [rt.cpan.org #87906] pthreads header problem and Inline::C
Date: Mon, 25 Nov 2013 07:19:16 -0800
To: bug-Perl-Dist-Strawberry [...] rt.cpan.org
From: David Jacobowitz <david.jacobowitz [...] gmail.com>
Hi guys, I may have to provide a more complex script to show the problem with the 'undef' solution. I'll try to get to it today. My project is largish has five threads, so I'll have to cut it down for the bug. I should have submitted something that shows the undef problem in the first place. My bad. -- dave j On Mon, Nov 25, 2013 at 6:41 AM, Sisyphus via RT < bug-Perl-Dist-Strawberry@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > > > On Sun Nov 24 19:39:14 2013, sisyphus1@optusnet.com.au wrote:
> > > > > > -----Original Message----- > > From: kmx via RT > > Sent: Monday, November 25, 2013 9:19 AM > > To: david.jacobowitz@gmail.com > > Cc: sisyphus1@optusnet.com.au > > Subject: [rt.cpan.org #87906] pthreads header problem and Inline::C > >
> > > <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > > > > > > > I have put into Cc: Sisyphus - the author of Inline::C + AFAIK
> occasional
> > > Strawberry Perl user - he might have a better comment on this issue.
> > Sorry - when I wrote my reply I didn't realise that Dave had provided > sample scripts. The "works.pl" works fine for me, as expected. > I've also grabbed "fails.pl" and inserted the "#undef > PTHREAD_CREATE_JOINABLE" immediately before the inclusion of pthread.h. > That script (ie "fails.h") then runs fine for me ... no segfaults at all !! > > Admittedly I don't have the exact same version of Strawberry as Dave was > running. I tried on Strawberry Perls (portable) 5.16.0, and 5.18.0. I also > tried it on a mingw.org compiler-built 5.16.0 - again no problems. > > Seems odd. > kmx, did you try running "fails.h" (amended as per above) on any of your > Strawberry Perl installations ? > > Cheers, > Rob >
CC: sisyphus1 [...] optusnet.com.au
Subject: Re: [rt.cpan.org #87906] pthreads header problem and Inline::C
Date: Tue, 26 Nov 2013 19:26:43 -0800
To: bug-Perl-Dist-Strawberry [...] rt.cpan.org
From: David Jacobowitz <david.jacobowitz [...] gmail.com>
Well, I can't reproduce the problem with the #undef solution now, either. I'm sorry, guys. If it pops up I'll append this bug again. Thanks for Inline::C, Sisyphus. It's a brilliant. On 11/25/2013 6:41 AM, Sisyphus via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > > > On Sun Nov 24 19:39:14 2013, sisyphus1@optusnet.com.au wrote:
>> >> -----Original Message----- >> From: kmx via RT >> Sent: Monday, November 25, 2013 9:19 AM >> To: david.jacobowitz@gmail.com >> Cc: sisyphus1@optusnet.com.au >> Subject: [rt.cpan.org #87906] pthreads header problem and Inline::C >>
>>> <URL: https://rt.cpan.org/Ticket/Display.html?id=87906 > >>> >>> I have put into Cc: Sisyphus - the author of Inline::C + AFAIK occasional >>> Strawberry Perl user - he might have a better comment on this issue.
> Sorry - when I wrote my reply I didn't realise that Dave had provided sample scripts. The "works.pl" works fine for me, as expected. > I've also grabbed "fails.pl" and inserted the "#undef PTHREAD_CREATE_JOINABLE" immediately before the inclusion of pthread.h. > That script (ie "fails.h") then runs fine for me ... no segfaults at all !! > > Admittedly I don't have the exact same version of Strawberry as Dave was running. I tried on Strawberry Perls (portable) 5.16.0, and 5.18.0. I also tried it on a mingw.org compiler-built 5.16.0 - again no problems. > > Seems odd. > kmx, did you try running "fails.h" (amended as per above) on any of your Strawberry Perl installations ? > > Cheers, > Rob