Thread support in cygwin!

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Thread support in cygwin!

Do Nguyen Luong
Hi, I'm trying to port a program used pthread in Linux to Windows.In cygwin, I compiled it but when executing I got this message : Threads are not supported
In Linux, it works fine.
Then in Cygwin I write this simple program :

#include <pthread.h>
#include <unistd.h> 
#include <stdio.h> 
int main()
{
#ifdef _POSIX_THREADS
        printf("sysconf(_SC_THREADS): %d\n", sysconf(_SC_THREADS));
#else
        printf("_POSIX_THREADS not defined\n");
#endif
        return 0;
}

And I get :
sysconf(_SC_THREADS): -1

Is that mean cygwin doesn't support threads? Or I missed some package?
Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Joost Kraaijeveld
On Wed, 2006-04-12 at 21:53 -0700, Do Nguyen Luong wrote:

> #include <pthread.h>
> #include <unistd.h>
> #include <stdio.h>
> int main()
> {
> #ifdef _POSIX_THREADS
>         printf("sysconf(_SC_THREADS): %d\n", sysconf(_SC_THREADS));
> #else
>         printf("_POSIX_THREADS not defined\n");
> #endif
>         return 0;
> }
>
> And I get :
> sysconf(_SC_THREADS): -1
>
> Is that mean cygwin doesn't support threads? Or I missed some package?
No, it means that _POSIX_THREADS  is not defined.

For the pthread support of Cygwin you can look at Cygwin's pthread.h
(which basically says that this is implemented:
http://www.opengroup.org/onlinepubs/7908799/xsh/pthread.h.html ) or at
the Cygwin API docs at http://cygwin.com/cygwin-api/std-posix.html#AEN85
(which seems a little sparse).


--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Samuel Thibault
Joost Kraaijeveld, le Thu 13 Apr 2006 08:10:15 +0200, a écrit :
> No, it means that _POSIX_THREADS  is not defined.

Cygwin should define it.

Regards,
Samuel

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Joost Kraaijeveld
On Thu, 2006-04-13 at 11:00 +0200, Samuel Thibault wrote:

> Joost Kraaijeveld, le Thu 13 Apr 2006 10:45:39 +0200, a écrit :
> > On Thu, 2006-04-13 at 09:42 +0200, Samuel Thibault wrote:
> > > Joost Kraaijeveld, le Thu 13 Apr 2006 08:10:15 +0200, a écrit :
> > > > No, it means that _POSIX_THREADS  is not defined.
> > >
> > > Cygwin should define it.
> > Why?
>
> In unistd.h I mean. (And by really looking at it, unistd.h includes
> sys/unistd.h which itself includes sys/features.h, which defines it, so
> the problem here is probably that the user includes pthread.h instead of
> unistd.h (I haven't kept the mail)).

You are right here: see also
http://www.opengroup.org/onlinepubs/007908799/xsh/unistd.h.html or
http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
(The Single UNIX ® Specification, Version 2 or 3).

Although not required by a pthread spec (as far as I can see) it might
be a good idea to include (the pthread part) unistd.h in the pthread.h
as Linux and pthreads-win32 seem to do.

--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Corinna Vinschen-2
On Apr 13 11:36, Joost Kraaijeveld wrote:

> On Thu, 2006-04-13 at 11:00 +0200, Samuel Thibault wrote:
> > Joost Kraaijeveld, le Thu 13 Apr 2006 10:45:39 +0200, a écrit :
> > > On Thu, 2006-04-13 at 09:42 +0200, Samuel Thibault wrote:
> > > > Joost Kraaijeveld, le Thu 13 Apr 2006 08:10:15 +0200, a écrit :
> > > > > No, it means that _POSIX_THREADS  is not defined.
> > > >
> > > > Cygwin should define it.
> > > Why?
> >
> > In unistd.h I mean. (And by really looking at it, unistd.h includes
> > sys/unistd.h which itself includes sys/features.h, which defines it, so
> > the problem here is probably that the user includes pthread.h instead of
> > unistd.h (I haven't kept the mail)).
>
> You are right here: see also
> http://www.opengroup.org/onlinepubs/007908799/xsh/unistd.h.html or
> http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
> (The Single UNIX ® Specification, Version 2 or 3).
>
> Although not required by a pthread spec (as far as I can see) it might
> be a good idea to include (the pthread part) unistd.h in the pthread.h
> as Linux and pthreads-win32 seem to do.

As far as I can see, Linux doesn't:

  $ echo "#include <pthread.h>" > x.c
  $ gcc -M x.c
  x.o: x.c /usr/include/pthread.h /usr/include/features.h \
    /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h /usr/include/sched.h \
    /usr/include/bits/types.h /usr/include/bits/wordsize.h \
    /usr/lib/gcc/i386-redhat-linux/3.4.5/include/stddef.h \
    /usr/include/bits/typesizes.h /usr/include/time.h \
    /usr/include/bits/sched.h /usr/include/bits/time.h \
    /usr/include/signal.h /usr/include/bits/sigset.h \
    /usr/include/bits/pthreadtypes.h /usr/include/bits/initspin.h \
    /usr/include/bits/sigthread.h

And it doesn't make sense to me.  The _POSIX_THREAD* values are already
included through /usr/include/features.h and the _SC_THREAD* values are
only used for sysconf, which requires to include unistd.h anyway.

As for Cygwin:

  $ gcc -M x.c
  x.o: x.c /usr/include/pthread.h /usr/include/sys/types.h \
    /usr/include/_ansi.h /usr/include/newlib.h /usr/include/sys/config.h \
    /usr/include/machine/ieeefp.h /usr/include/cygwin/config.h \
    /usr/include/machine/_types.h /usr/include/sys/_types.h \
    /usr/include/sys/lock.h \
    /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h \
    /usr/include/machine/types.h /usr/include/sys/features.h \
    /usr/include/cygwin/types.h /usr/include/sys/sysmacros.h \
    /usr/include/stdint.h /usr/include/endian.h /usr/include/signal.h \
    /usr/include/_ansi.h /usr/include/sys/signal.h \
    /usr/include/cygwin/signal.h /usr/include/sched.h /usr/include/time.h \
    /usr/include/sys/reent.h /usr/include/machine/time.h \
    /usr/include/cygwin/time.h

You can see that /usr/include/sys/features.h is included, so the
_POSIX_THREAD* defines are available.

I see only one problem here, which is that _SC_THREAD* values are
currently not supported by sysconf(), hence returning -1.  I'll add
the handling for these values to sysconf().


Corinna

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Do Nguyen Luong
Thank you for answering me!

But I think _POSIX_THREADS definitely  is defined. Corinna said the problem was that _SC_THREAD* values were currently not supported by sysconf(). So cygwin supports threads and I can ignore sysconf()??
Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Samuel Thibault
Do Nguyen Luong, le Thu 13 Apr 2006 05:57:17 -0700, a écrit :
> But I think _POSIX_THREADS definitely  is defined. Corinna said the problem
> was that _SC_THREAD* values were currently not supported by sysconf(). So
> cygwin supports threads and I can ignore sysconf()??

For now, yes. On the long run, you should be able to rely on sysconf().

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: Thread support in cygwin!

Joost Kraaijeveld
In reply to this post by Corinna Vinschen-2
On Thu, 2006-04-13 at 14:10 +0200, Corinna Vinschen wrote:
> You can see that /usr/include/sys/features.h is included, so the
> _POSIX_THREAD* defines are available.
Not on my Linux (Debian Etch AMD64). The only place where I can find a
define for _POSIX_THREAD is in unistd.h, and not in feature.h (where it
is in my cygwin)

BTW: I misread the code of OP, I thought that that "__POSIX_THREADS not
defined" printed, so my remarks were slightly misplaced.


--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/