Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #127167
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c, comp.lang.c++ |
| Subject | Re: How do you do something like this? |
| Date | 2018-02-28 22:35 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <p777bj$gbe$2@dont-email.me> (permalink) |
| References | (3 earlier) <dv44me-h94.ln1@ruby.opensrc.club> <15d6d799-4d29-cb8b-e7a4-1e48fbece7ad@verizon.net> <p74ksb$1k43$1@gioia.aioe.org> <p75r22$a9o$1@dont-email.me> <lnh8q1gfea.fsf@kst-u.example.com> |
Cross-posted to 2 groups.
On 28/02/18 19:03, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 27/02/18 23:07, Real Troll wrote:
>>> On 27/02/2018 13:30, James R. Kuyper wrote:
>>>> On 02/22/2018 07:48 PM, Egor wrote:
>>>>> In comp.lang.c Juha Nieminen <nospam@thanks.invalid> wrote:
>>>>>> I thought C++11 introduced sleep_for(). Why not use the standard
>>>>>> function?
>>>>> OP posted the question to both comp.lang.c and comp.lang.c++, so I
>>>>> provided a C-oriented answer.
>>>>
>>>> A C-oriented answer using C2011 could use thrd_sleep()
>>>>
>>> This one doesn't even compile in any of the compiler I have tried:
>>>
>>> GNU G++,
>>> Embarcadero
>>> Visual Studio 2010, 2013, 2015, 2017
>>>
>>>> #include <threads.h>
>>>> #include <time.h>
>>>> #include <stdio.h>
>>>
>>>> int main(void)
>>>> {
>>>> printf("Time: %s", ctime(&(time_t){time(NULL)}));
>>>> thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); // sleep 1 sec
>>>> printf("Time: %s", ctime(&(time_t){time(NULL)}));
>>>> }
>>
>> Works fine for me with gcc. Did you remember to use "-std=c11", or a
>> gcc version new enough to have "-std=gnu11" as the default? Did you use
>> a new enough gcc? (I think 4.9 is needed.) Did you use a library with
>> the right support (not a Windows gcc version that uses MS's old and
>> limited C libraries)?
>
> On Linux systems, gcc typically uses GNU libc by default, and GNU
> libc doesn't support <threads.h>. Specifying -std=... doesn't help.
> I don't think Visual Studio supports it either. (<threads.h> is
> optional, so this doesn't mean these implementations are non-conforming
> as long as they predefine __STDC_NO_THREADS__.)
>
> On Debian-based systems, you can install an alternative C library,
> MUSL, which does support <threads.h>. You have to use a wrapper
> called musl-gcc to compile with it.
>
Oh, you are correct. The gcc I tested was using MUSL.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How do you do something like this? G B <gb@gb.com> - 2018-02-13 01:35 +0000
Re: How do you do something like this? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-02-13 02:02 +0000
Re: How do you do something like this? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2018-02-13 03:53 +0100
Re: How do you do something like this? bartc <bc@freeuk.com> - 2018-02-13 11:50 +0000
Re: How do you do something like this? legalize+jeeves@mail.xmission.com (Richard) - 2018-02-13 21:34 +0000
Re: How do you do something like this? bartc <bc@freeuk.com> - 2018-02-13 22:01 +0000
Re: How do you do something like this? Egor <egor@ruby.local> - 2018-02-13 13:56 +0200
Re: How do you do something like this? Juha Nieminen <nospam@thanks.invalid> - 2018-02-19 06:28 +0000
Re: How do you do something like this? Egor <egor@ruby.local> - 2018-02-23 02:48 +0200
Re: How do you do something like this? "James R. Kuyper" <jameskuyper@verizon.net> - 2018-02-27 08:30 -0500
Re: How do you do something like this? Keith Thompson <kst-u@mib.org> - 2018-02-27 09:07 -0800
Re: How do you do something like this? Real Troll <Real.Troll@Trolls.com> - 2018-02-27 18:07 -0400
Re: How do you do something like this? David Brown <david.brown@hesbynett.no> - 2018-02-28 09:59 +0100
Re: How do you do something like this? Keith Thompson <kst-u@mib.org> - 2018-02-28 10:03 -0800
Re: How do you do something like this? David Brown <david.brown@hesbynett.no> - 2018-02-28 22:35 +0100
Re: How do you do something like this? Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 13:07 -0800
Re: How do you do something like this? Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 17:01 -0800
Re: How do you do something like this? Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 21:11 -0800
Re: How do you do something like this? Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 13:53 -0800
Re: How do you do something like this? Egor <egor@ruby.local> - 2018-03-05 14:48 +0200
csiph-web