Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #88973 > unrolled thread

Found a use case for `const` by value return, a shared queue

Started by"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
First post2023-02-04 22:32 +0100
Last post2023-03-07 17:37 +0100
Articles 20 on this page of 70 — 14 participants

Back to article view | Back to comp.lang.c++


Contents

  Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-04 22:32 +0100
    Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 15:37 +0100
      Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:45 +0100
    Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-05 12:49 -0800
      Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:39 +0100
        Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 22:09 +0100
          Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-06 21:35 +0000
            Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 23:44 +0100
              Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:34 +0000
              Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-07 07:42 -0800
                Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-07 17:34 +0100
                  Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 07:51 -0800
                    Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-24 18:48 +0100
                      Re: Found a use case for `const` by value return, a shared queue Daniel <danielaparker@gmail.com> - 2023-02-26 09:50 -0800
                        Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:38 -0800
                      Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:43 -0800
                        Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-03-06 15:51 +0100
                Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 16:35 +0000
                  Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-22 06:28 -0800
                    Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-22 15:01 +0000
                      Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 08:34 -0800
            Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 01:02 +0200
              Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:27 +0000
                Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 08:55 +0200
                  Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-07 12:11 -0800
            Re: Found a use case for `const` by value return, a shared queue James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-07 00:19 -0500
              Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 21:41 -0800
              Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 16:49 +0000
                Re: Found a use case for `const` by value return, a shared queue red floyd <no.spam.here@its.invalid> - 2023-02-08 11:11 -0800
                  Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 00:40 +0000
                    Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 17:15 -0800
                      Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 03:07 +0000
                        Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-09 04:54 +0100
                          Re: Found a use case for `const` by value return, a shared queue Öö Tiib <ootiib@hot.ee> - 2023-02-08 23:38 -0800
                            Re: Found a use case for `const` by value return, a shared queue David Brown <david.brown@hesbynett.no> - 2023-02-09 09:10 +0100
    Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-03 19:51 +0100
      Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-03 12:45 -0800
        Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 05:38 +0100
          Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:25 -0800
            Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:19 +0100
              Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:41 -0800
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:11 +0100
      Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 09:53 +0000
        Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 15:38 +0100
          Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 15:28 +0000
            Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:17 +0100
              Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:21 +0000
                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:39 +0100
                  Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:57 +0000
                    Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:06 +0100
                      Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:10 +0100
                      Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 17:14 +0000
                        Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:41 +0100
                          Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 20:07 +0100
                            Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:26 -0800
                              Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:18 +0100
                                Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:37 -0800
                                  Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 05:52 +0100
                                    Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:29 -0800
                                    Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:42 -0800
                          Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 09:18 +0000
                            Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 11:18 +0100
                              Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 10:26 +0000
                                Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:10 +0100
                                  Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 17:07 +0000
                                    Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 06:44 +0100
                                      Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 09:31 +0000
                                        Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 14:45 +0100
                                          Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 15:59 +0000
                                            Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 17:37 +0100

Page 1 of 4  [1] 2 3 4  Next page →


#88973 — Found a use case for `const` by value return, a shared queue

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-04 22:32 +0100
SubjectFound a use case for `const` by value return, a shared queue
Message-ID<trmist$24rbq$1@dont-email.me>
I finally encountered a use for `const T` as function return type.

This code appears to work well for the single purpose it's been used 
for, but it's not tested or even used extensively. And that includes 
that I haven't even tested/used that `const T` return function yet. But:


     template< class Item >
     class Shared_queue_
     {
         queue<Item>     m_queue;

         mutable mutex                   m_mutex;
         mutable condition_variable      m_condition;

         auto length() const -> int      { return int_size_of( m_queue ); }
         auto is_empty() const -> bool   { return m_queue.empty(); }

     public:
         class Access:
             public Movable
         {
             friend class Shared_queue_;

             Shared_queue_*      m_p_queue;
             Mutex_lock          m_mutex_lock;

             Access( Shared_queue_& q ):
                 m_p_queue( &q ),
                 m_mutex_lock( q.m_mutex )
             {}

             Access( const Shared_queue_& q ):
                 m_p_queue( &q ),
                 m_mutex_lock( q.m_mutex )
             {}

         public:
             auto length() const -> int      { return m_p_queue->length(); }
             auto is_empty() const -> bool   { return 
m_p_queue->is_empty(); }

             void wait_for_items()
             {
                 if( not is_empty() ) { return; }
                 m_p_queue->m_condition.wait( m_mutex_lock, [&]() -> 
bool { return not is_empty(); } );
             }

             auto wait_for_items_for( const Duration duration )
                 -> bool
             {
                 if( not is_empty() ) { return true; }
                 // TODO: handle possible overflow in 
`steady_clock::now() + duration`.
                 const bool timed_out = not m_p_queue->m_condition.wait_for(
                     m_mutex_lock, duration, [&]() -> bool { return not 
is_empty(); }
                     );
                 return not timed_out;
             }

             void enq( Item item, const bool notify = true )
             {
                 m_p_queue->m_queue.push( move( item ) );
                 if( notify ) { m_p_queue->m_condition.notify_one(); }
             }

             auto deq() -> Item
             {
                 wait_for_items();
                 hopefully( not is_empty() )
                     or FSM_FAIL( "Waited for items but got none; queue 
is empty." );
                 return popped_front_of( m_p_queue->m_queue );
             }
         };

         auto access() -> Access                 { return Access( *this ); }
         auto access() const -> const Access     { return Access( *this ); }
     };


- Alf

[toc] | [next] | [standalone]


#88975

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-05 15:37 +0100
Message-ID<troevp$2hphi$1@dont-email.me>
In reply to#88973
On 2023-02-04 10:32 PM, Alf P. Steinbach wrote:
> I finally encountered a use for `const T` as function return type.
> 
> This code appears to work well for the single purpose it's been used 
> for, but it's not tested or even used extensively. And that includes 
> that I haven't even tested/used that `const T` return function yet. But:
> 
> 
>      template< class Item >
>      class Shared_queue_
>      {
>          queue<Item>     m_queue;
> 
>          mutable mutex                   m_mutex;
>          mutable condition_variable      m_condition;
> 
>          auto length() const -> int      { return int_size_of( m_queue ); }
>          auto is_empty() const -> bool   { return m_queue.empty(); }
> 
>      public:
>          class Access:
>              public Movable
>          {
>              friend class Shared_queue_;
> 
>              Shared_queue_*      m_p_queue;
>              Mutex_lock          m_mutex_lock;
> 
>              Access( Shared_queue_& q ):
>                  m_p_queue( &q ),
>                  m_mutex_lock( q.m_mutex )
>              {}
> 
>              Access( const Shared_queue_& q ):
>                  m_p_queue( &q ),
>                  m_mutex_lock( q.m_mutex )
>              {}
> 
>          public:
>              auto length() const -> int      { return m_p_queue->length(); }
>              auto is_empty() const -> bool   { return m_p_queue->is_empty(); }
> 
>              void wait_for_items()
>              {
>                  if( not is_empty() ) { return; }
>                  m_p_queue->m_condition.wait( m_mutex_lock, [&]() -> bool { return not is_empty(); } );
>              }
> 
>              auto wait_for_items_for( const Duration duration )
>                  -> bool
>              {
>                  if( not is_empty() ) { return true; }
>                  // TODO: handle possible overflow in `steady_clock::now() + duration`.
>                  const bool timed_out = not m_p_queue->m_condition.wait_for(
>                      m_mutex_lock, duration, [&]() -> bool { return not is_empty(); }
>                      );
>                  return not timed_out;
>              }
> 
>              void enq( Item item, const bool notify = true )
>              {
>                  m_p_queue->m_queue.push( move( item ) );
>                  if( notify ) { m_p_queue->m_condition.notify_one(); }
>              }
> 
>              auto deq() -> Item
>              {
>                  wait_for_items();
>                  hopefully( not is_empty() )
>                      or FSM_FAIL( "Waited for items but got none; queue is empty." );
>                  return popped_front_of( m_p_queue->m_queue );
>              }
>          };
> 
>          auto access() -> Access                 { return Access( *this ); }
>          auto access() const -> const Access     { return Access( *this ); }
>      };

Right after I went to bed last night it hit me that the `const` `access` 
function couldn't possibly work as written, because the `Access` 
constructor it calls tries to initialize a `Shared_queue_*` with a 
`const Shared_queue_*`.

I haven't yet tried to call it (functions in templates can be very wrong 
so that they wouldn't compile if used, as long as they're not actually 
used), but after two cups of coffee I now think the same.

I saw two possible solutions before I went to sleep:

* use a union for the proxy object's pointer-to-queue, or
* use separate proxy types for the mutable and const cases.

I am not at all sure that type punning `const T*` and `T*` via a union, 
even if it is dynamically safe and correct from a machine code point of 
view, is formally allowed in C++?

With separate proxy types a `Mutable_access_` can inherit from a 
`Const_access_` and have the pointer type or constness thereof as a 
template parameter, but though it's type-wise clean it also feels like a 
kludge; complex. Furthermore the `const` on the return type will then 
not matter. So is it that with formally correct C++ I have not run into 
a case where `const` on a by-value return type is reasonable?


- Alf

[toc] | [prev] | [next] | [standalone]


#88978

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-05 22:45 +0100
Message-ID<trp81s$2n7fu$2@dont-email.me>
In reply to#88975
On 2023-02-05 3:37 PM, Alf P. Steinbach wrote:
> On 2023-02-04 10:32 PM, Alf P. Steinbach wrote:
>> I finally encountered a use for `const T` as function return type.
>>
>> This code appears to work well for the single purpose it's been used 
>> for, but it's not tested or even used extensively. And that includes 
>> that I haven't even tested/used that `const T` return function yet. But:
>>
>>
>>      template< class Item >
>>      class Shared_queue_
>>      {
>>          queue<Item>     m_queue;
>>
>>          mutable mutex                   m_mutex;
>>          mutable condition_variable      m_condition;
>>
>>          auto length() const -> int      { return int_size_of( m_queue 
>> ); }
>>          auto is_empty() const -> bool   { return m_queue.empty(); }
>>
>>      public:
>>          class Access:
>>              public Movable
>>          {
>>              friend class Shared_queue_;
>>
>>              Shared_queue_*      m_p_queue;
>>              Mutex_lock          m_mutex_lock;
>>
>>              Access( Shared_queue_& q ):
>>                  m_p_queue( &q ),
>>                  m_mutex_lock( q.m_mutex )
>>              {}
>>
>>              Access( const Shared_queue_& q ):
>>                  m_p_queue( &q ),
>>                  m_mutex_lock( q.m_mutex )
>>              {}
>>
>>          public:
>>              auto length() const -> int      { return 
>> m_p_queue->length(); }
>>              auto is_empty() const -> bool   { return 
>> m_p_queue->is_empty(); }
>>
>>              void wait_for_items()
>>              {
>>                  if( not is_empty() ) { return; }
>>                  m_p_queue->m_condition.wait( m_mutex_lock, [&]() -> 
>> bool { return not is_empty(); } );
>>              }
>>
>>              auto wait_for_items_for( const Duration duration )
>>                  -> bool
>>              {
>>                  if( not is_empty() ) { return true; }
>>                  // TODO: handle possible overflow in 
>> `steady_clock::now() + duration`.
>>                  const bool timed_out = not 
>> m_p_queue->m_condition.wait_for(
>>                      m_mutex_lock, duration, [&]() -> bool { return 
>> not is_empty(); }
>>                      );
>>                  return not timed_out;
>>              }
>>
>>              void enq( Item item, const bool notify = true )
>>              {
>>                  m_p_queue->m_queue.push( move( item ) );
>>                  if( notify ) { m_p_queue->m_condition.notify_one(); }
>>              }
>>
>>              auto deq() -> Item
>>              {
>>                  wait_for_items();
>>                  hopefully( not is_empty() )
>>                      or FSM_FAIL( "Waited for items but got none; 
>> queue is empty." );
>>                  return popped_front_of( m_p_queue->m_queue );
>>              }
>>          };
>>
>>          auto access() -> Access                 { return Access( 
>> *this ); }
>>          auto access() const -> const Access     { return Access( 
>> *this ); }
>>      };
> 
> Right after I went to bed last night it hit me that the `const` `access` 
> function couldn't possibly work as written, because the `Access` 
> constructor it calls tries to initialize a `Shared_queue_*` with a 
> `const Shared_queue_*`.
> 
> I haven't yet tried to call it (functions in templates can be very wrong 
> so that they wouldn't compile if used, as long as they're not actually 
> used), but after two cups of coffee I now think the same.
> 
> I saw two possible solutions before I went to sleep:
> 
> * use a union for the proxy object's pointer-to-queue, or
> * use separate proxy types for the mutable and const cases.
> 
> I am not at all sure that type punning `const T*` and `T*` via a union, 
> even if it is dynamically safe and correct from a machine code point of 
> view, is formally allowed in C++?
> 
> With separate proxy types a `Mutable_access_` can inherit from a 
> `Const_access_` and have the pointer type or constness thereof as a 
> template parameter, but though it's type-wise clean it also feels like a 
> kludge; complex. Furthermore the `const` on the return type will then 
> not matter. So is it that with formally correct C++ I have not run into 
> a case where `const` on a by-value return type is reasonable?

I landed on a simple type safe solution with a bit of overhead.

Namely using a `std::variant` for the proxy's pointer to its referent.


     template< class Item >
     class Shared_queue_
     {
         queue<Item>     m_queue;

         mutable mutex                   m_mutex;
         mutable condition_variable      m_condition;

         auto length() const -> int      { return int_size_of( m_queue ); }
         auto is_empty() const -> bool   { return m_queue.empty(); }

     public:
         class Access:
             public Movable
         {
             friend class Shared_queue_;
             using Q_ptr = variant<Shared_queue_*, const Shared_queue_*>;

             Q_ptr               m_p_queue;
             Mutex_lock          m_mutex_lock;

             Access( Shared_queue_& q ): m_p_queue( &q ), m_mutex_lock( 
q.m_mutex ) {}
             Access( const Shared_queue_& q ): m_p_queue( &q ), 
m_mutex_lock( q.m_mutex ) {}

             auto shared_queue() -> Shared_queue_& { return 
*get<Shared_queue_*>( m_p_queue ); }

             auto shared_queue() const
                 -> const Shared_queue_&
             { return *(m_p_queue.index() == 0? get<0>( m_p_queue ) : 
get<1>( m_p_queue )); }

         public:
             auto length() const -> int      { return 
shared_queue().length(); }
             auto is_empty() const -> bool   { return 
shared_queue().is_empty(); }

             void wait_for_items()
             {
                 if( not is_empty() ) { return; }
                 shared_queue().m_condition.wait( m_mutex_lock, [&]() -> 
bool { return not is_empty(); } );
             }

             auto wait_for_items_for( const Duration duration )
                 -> bool
             {
                 if( not is_empty() ) { return true; }
                 // TODO: handle possible overflow in 
`steady_clock::now() + duration`.
                 const bool timed_out = not 
shared_queue().m_condition.wait_for(
                     m_mutex_lock, duration, [&]() -> bool { return not 
is_empty(); }
                     );
                 return not timed_out;
             }

             void enq( Item item, const bool notify = true )
             {
                 shared_queue().m_queue.push( move( item ) );
                 if( notify ) { shared_queue().m_condition.notify_one(); }
             }

             auto deq() -> Item
             {
                 wait_for_items();
                 hopefully( not is_empty() )
                     or FSM_FAIL( "Waited for items but got none; 
shared_queue is empty." );
                 return popped_front_of( shared_queue().m_queue );
             }
         };

         auto access() -> Access                 { return Access( *this ); }
         auto access() const -> const Access     { return Access( *this ); }
     };

- Alf

[toc] | [prev] | [next] | [standalone]


#88976

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2023-02-05 12:49 -0800
Message-ID<trp4o0$2mhfk$2@dont-email.me>
In reply to#88973
On 2/4/2023 1:32 PM, Alf P. Steinbach wrote:
> I finally encountered a use for `const T` as function return type.
> 
> This code appears to work well for the single purpose it's been used 
> for, but it's not tested or even used extensively. And that includes 
> that I haven't even tested/used that `const T` return function yet. But:
> 
> 
>      template< class Item >
>      class Shared_queue_
>      {
>          queue<Item>     m_queue;
> 
>          mutable mutex                   m_mutex;
>          mutable condition_variable      m_condition;
> 
>          auto length() const -> int      { return int_size_of( m_queue ); }
>          auto is_empty() const -> bool   { return m_queue.empty(); }
> 
>      public:
>          class Access:
>              public Movable
>          {
>              friend class Shared_queue_;
> 
>              Shared_queue_*      m_p_queue;
>              Mutex_lock          m_mutex_lock;
> 
>              Access( Shared_queue_& q ):
>                  m_p_queue( &q ),
>                  m_mutex_lock( q.m_mutex )
>              {}
> 
>              Access( const Shared_queue_& q ):
>                  m_p_queue( &q ),
>                  m_mutex_lock( q.m_mutex )
>              {}
> 
>          public:
>              auto length() const -> int      { return 
> m_p_queue->length(); }
>              auto is_empty() const -> bool   { return 
> m_p_queue->is_empty(); }
> 
>              void wait_for_items()
>              {
>                  if( not is_empty() ) { return; }
>                  m_p_queue->m_condition.wait( m_mutex_lock, [&]() -> 
> bool { return not is_empty(); } );
>              }
> 
>              auto wait_for_items_for( const Duration duration )
>                  -> bool
>              {
>                  if( not is_empty() ) { return true; }
>                  // TODO: handle possible overflow in 
> `steady_clock::now() + duration`.
>                  const bool timed_out = not 
> m_p_queue->m_condition.wait_for(
>                      m_mutex_lock, duration, [&]() -> bool { return not 
> is_empty(); }
>                      );
>                  return not timed_out;
>              }
> 
>              void enq( Item item, const bool notify = true )
>              {
>                  m_p_queue->m_queue.push( move( item ) );
>                  if( notify ) { m_p_queue->m_condition.notify_one(); }
>              }
[...]

Signalling a condition variable while the mutex is locked is not that 
efficient unless the condvar has wait morphing. God, I have not thought 
about wait morphing for a long time. Thanks for making me think of it!


[toc] | [prev] | [next] | [standalone]


#88977

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-05 22:39 +0100
Message-ID<trp7ne$2n7fu$1@dont-email.me>
In reply to#88976
On 2023-02-05 9:49 PM, Chris M. Thomasson wrote:
> On 2/4/2023 1:32 PM, Alf P. Steinbach wrote:
>> I finally encountered a use for `const T` as function return type.
>>
>> This code appears to work well for the single purpose it's been used 
>> for, but it's not tested or even used extensively. And that includes 
>> that I haven't even tested/used that `const T` return function yet. But:
>>
>>
>>      template< class Item >
>>      class Shared_queue_
>>      {
>>          queue<Item>     m_queue;
>>
>>          mutable mutex                   m_mutex;
>>          mutable condition_variable      m_condition;
>>
>>          auto length() const -> int      { return int_size_of( m_queue 
>> ); }
>>          auto is_empty() const -> bool   { return m_queue.empty(); }
>>
>>      public:
>>          class Access:
>>              public Movable
>>          {
>>              friend class Shared_queue_;
>>
>>              Shared_queue_*      m_p_queue;
>>              Mutex_lock          m_mutex_lock;
>>
>>              Access( Shared_queue_& q ):
>>                  m_p_queue( &q ),
>>                  m_mutex_lock( q.m_mutex )
>>              {}
>>
>>              Access( const Shared_queue_& q ):
>>                  m_p_queue( &q ),
>>                  m_mutex_lock( q.m_mutex )
>>              {}
>>
>>          public:
>>              auto length() const -> int      { return 
>> m_p_queue->length(); }
>>              auto is_empty() const -> bool   { return 
>> m_p_queue->is_empty(); }
>>
>>              void wait_for_items()
>>              {
>>                  if( not is_empty() ) { return; }
>>                  m_p_queue->m_condition.wait( m_mutex_lock, [&]() -> 
>> bool { return not is_empty(); } );
>>              }
>>
>>              auto wait_for_items_for( const Duration duration )
>>                  -> bool
>>              {
>>                  if( not is_empty() ) { return true; }
>>                  // TODO: handle possible overflow in 
>> `steady_clock::now() + duration`.
>>                  const bool timed_out = not 
>> m_p_queue->m_condition.wait_for(
>>                      m_mutex_lock, duration, [&]() -> bool { return 
>> not is_empty(); }
>>                      );
>>                  return not timed_out;
>>              }
>>
>>              void enq( Item item, const bool notify = true )
>>              {
>>                  m_p_queue->m_queue.push( move( item ) );
>>                  if( notify ) { m_p_queue->m_condition.notify_one(); }
>>              }
> [...]
> 
> Signalling a condition variable while the mutex is locked is not that 
> efficient unless the condvar has wait morphing. God, I have not thought 
> about wait morphing for a long time. Thanks for making me think of it!

Thanks. I don't know yet how to handle that with the RAII-based access 
scheme. Perhaps set a count of number of signals to issue then do that 
in the Access destructor.

All this C++ multithreading is fairly new to me.

Previous experience mainly limited to (1) implementing multitasking in 
6502 or something assembly at school in 1984 or so, using an HP 64000 
development system (that was really really cool!), and implementing 
`longjmp` based coroutines in a very very unsafe way in the 1990's, 
unfortunately with the code picked up and used by a hospital in New 
York, which made me really scared of what I might be responsible for. 
Oh, and I forgot, also at school in 1984 or so, an Othello game where 
the computer found its next most likely moves while the user was 
thinking of his/her move. Due to the apparently instant moves of the 
program (it had had much time to think, invisibly) my teacher at first 
refused to believe it was not cheating of some kind; I had to show the 
debug output of the thinking process on a separate terminal...

- Alf

[toc] | [prev] | [next] | [standalone]


#88995

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-06 22:09 +0100
Message-ID<trrqae$375de$1@dont-email.me>
In reply to#88977
On 2023-02-05 10:39 PM, Alf P. Steinbach wrote:
> On 2023-02-05 9:49 PM, Chris M. Thomasson wrote:
>
>> Signalling a condition variable while the mutex is locked is not that 
>> efficient unless the condvar has wait morphing. God, I have not 
>> thought about wait morphing for a long time. Thanks for making me 
>> think of it!
> 
> Thanks. I don't know yet how to handle that with the RAII-based access 
> scheme. Perhaps set a count of number of signals to issue then do that 
> in the Access destructor.

Implementation of that idea, hopefully it makes sense and is technically 
correct:

     template< class Item >
     class Shared_queue_
     {
         queue<Item>     m_queue;

         mutable mutex                   m_mutex;
         mutable condition_variable      m_condition;

         auto length() const -> int      { return int_size_of( m_queue ); }
         auto is_empty() const -> bool   { return m_queue.empty(); }

     public:
         class Access:
             public Movable
         {
             friend class Shared_queue_;
             using Q_ptr = variant<Shared_queue_*, const Shared_queue_*>;

             Q_ptr               m_p_queue;
             Mutex_lock          m_mutex_lock;
             int                 m_n_notifications   = 0;

             Access( Shared_queue_& q ): m_p_queue( &q ), m_mutex_lock( 
q.m_mutex ) {}
             Access( const Shared_queue_& q ): m_p_queue( &q ), 
m_mutex_lock( q.m_mutex ) {}

             auto shared_queue() -> Shared_queue_& { return 
*get<Shared_queue_*>( m_p_queue ); }

             auto shared_queue() const
                 -> const Shared_queue_&
             { return *(m_p_queue.index() == 0? get<0>( m_p_queue ) : 
get<1>( m_p_queue )); }

         public:
             ~Access()
             {
                 m_mutex_lock.unlock();
                 repeat_times( m_n_notifications, [&]{
                     shared_queue().m_condition.notify_one();
                 } );
             }

             auto length() const -> int      { return 
shared_queue().length(); }
             auto is_empty() const -> bool   { return 
shared_queue().is_empty(); }

             void wait_for_items()
             {
                 if( not is_empty() ) { return; }
                 shared_queue().m_condition.wait( m_mutex_lock, [&]() -> 
bool { return not is_empty(); } );
             }

             auto wait_for_items_for( const Duration duration )
                 -> bool
             {
                 if( not is_empty() ) { return true; }
                 // TODO: handle possible overflow in 
`steady_clock::now() + duration`.
                 const bool timed_out = not 
shared_queue().m_condition.wait_for(
                     m_mutex_lock, duration, [&]() -> bool { return not 
is_empty(); }
                     );
                 return not timed_out;
             }

             void enq( Item item, const bool notify = true )
             {
                 shared_queue().m_queue.push( move( item ) );
                 m_n_notifications += notify;
             }

             auto deq() -> Item
             {
                 wait_for_items();
                 hopefully( not is_empty() )
                     or FSM_FAIL( "Waited for items but got none; 
shared_queue is empty." );
                 return popped_front_of( shared_queue().m_queue );
             }
         };

         auto access() -> Access                 { return Access( *this ); }
         auto access() const -> const Access     { return Access( *this ); }
     };

- Alf

[toc] | [prev] | [next] | [standalone]


#88996

Fromscott@slp53.sl.home (Scott Lurndal)
Date2023-02-06 21:35 +0000
Message-ID<CoeEL.1039063$GNG9.528495@fx18.iad>
In reply to#88995
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>On 2023-02-05 10:39 PM, Alf P. Steinbach wrote:
>> On 2023-02-05 9:49 PM, Chris M. Thomasson wrote:
>>
>>> Signalling a condition variable while the mutex is locked is not that 
>>> efficient unless the condvar has wait morphing. God, I have not 
>>> thought about wait morphing for a long time. Thanks for making me 
>>> think of it!
>> 
>> Thanks. I don't know yet how to handle that with the RAII-based access 
>> scheme. Perhaps set a count of number of signals to issue then do that 
>> in the Access destructor.
>
>Implementation of that idea, hopefully it makes sense and is technically 
>correct:

Leaving aside the odd syntactic choices, what is the function
of the class and why would it be of use?  How about providing
an example of use?

I don't recall 'not', 'and' and 'or' being C++ keywords.

What's the difference between "mutex" and "Mutex_lock" types?

Where is the mutex actually acquired?  It is released in the
destructor - does the undefined "Mutex_lock" class acquire the
mutex in some misguided attempt to apply RAII to locking?

IME, a critical region generally protects more just queue accesses;
it may also protect other data or make a certain code sequence atomic
with respect to other threads.   That's one of the many reasons that
I dislike the application of RAII to locking.

Whatever agent you used to post this wrapped many of the longer lines
which made it even less readable than your nonstandard syntax choices.

     m_mutex.lock();
     qe = m_queue.pop()
     m_mutex_unlock();

seems to be much cleaner and far more readable (and thus more maintainable).

The idea that locking can be solved using RAII universally is unviable.

/**
 * Execute I/O Control Blocks queued to this DLP instance.
 *
 * This is the main loop of the per-DLP instance thread.
 *
 * Loop until the d_exit flag is set to true.
 * Set d_exited flag when the thread terminates to notify
 * terminator that the thread terminated successfully.
 */
void
c_dlp::run(void)
{
    int diag;
    c_dlist   pending;
    char      tname[64];

    c_processor::set_this(d_processor);
    c_system::set_this(mp->get_system());
    c_memory::set_this(mp->get_system()->get_mem());

    snprintf(tname, sizeof(tname), "%04lu %s DLP",
	     d_channel, get_hardware_name());
    set_threadname(tname);

    pending.init();

    lock_thread();
    while (!d_exit) {
	while (pending.is_empty()) {
	    c_dlist_iterator di(&d_iocbs);
	    while (di.next()) {
		c_iocb *iocb = (c_iocb *)di.curr();

		iocb->remove();
		pending.insert(iocb);
	    }
	    if (!pending.is_empty()) break;
	    diag = pthread_cond_wait(&d_wait, &t_threadlock);
	    if (diag != 0) {
		d_logger->log("%04lu/00 Unexpected cond-wait result: %s\n",
			      d_channel, strerror(diag));
	    }
	    if (d_exit) break;
	}

	if (d_exit) break;

	unlock_thread();

	c_dlist_iterator worklist(&pending);
	while (worklist.next()) {
	    c_iocb * iocb = (c_iocb *)worklist.curr();
	    iocb->remove();

	    switch (iocb->get_op()) {
	    case IOD_CANCEL:
		cancel(iocb);
		break;
	    case IOD_READ:
		read(iocb);
		break;
	    case IOD_WRITE:
		write(iocb);
		break;
	    case IOD_TEST:
		if (iocb->get_op_var1() == IOD_TEST_IDENTIFY) {
		    set_rd(iocb, IOT_COMPLETE|IOT_EXT_RD_PRESENT,
				 0x0000, d_testid << 8);
		} else {
		    test(iocb);
		}
		break;
	    case IOD_ECHO:
		echo(iocb);
		break;
	    }
	}
	lock_thread();
	pending.init();
    }
    d_exited = true;

    unlock_thread();
}


>
>     template< class Item >
>     class Shared_queue_
>     {
>         queue<Item>     m_queue;
>
>         mutable mutex                   m_mutex;
>         mutable condition_variable      m_condition;
>
>         auto length() const -> int      { return int_size_of( m_queue ); }
>         auto is_empty() const -> bool   { return m_queue.empty(); }
>
>     public:
>         class Access:
>             public Movable
>         {
>             friend class Shared_queue_;
>             using Q_ptr = variant<Shared_queue_*, const Shared_queue_*>;
>
>             Q_ptr               m_p_queue;
>             Mutex_lock          m_mutex_lock;
>             int                 m_n_notifications   = 0;
>
>             Access( Shared_queue_& q ): m_p_queue( &q ), m_mutex_lock( 
>q.m_mutex ) {}
>             Access( const Shared_queue_& q ): m_p_queue( &q ), 
>m_mutex_lock( q.m_mutex ) {}
>
>             auto shared_queue() -> Shared_queue_& { return 
>*get<Shared_queue_*>( m_p_queue ); }
>
>             auto shared_queue() const
>                 -> const Shared_queue_&
>             { return *(m_p_queue.index() == 0? get<0>( m_p_queue ) : 
>get<1>( m_p_queue )); }
>
>         public:
>             ~Access()
>             {
>                 m_mutex_lock.unlock();
>                 repeat_times( m_n_notifications, [&]{
>                     shared_queue().m_condition.notify_one();
>                 } );
>             }
>
>             auto length() const -> int      { return 
>shared_queue().length(); }
>             auto is_empty() const -> bool   { return 
>shared_queue().is_empty(); }
>
>             void wait_for_items()
>             {
>                 if( not is_empty() ) { return; }
>                 shared_queue().m_condition.wait( m_mutex_lock, [&]() -> 
>bool { return not is_empty(); } );
>             }
>
>             auto wait_for_items_for( const Duration duration )
>                 -> bool
>             {
>                 if( not is_empty() ) { return true; }
>                 // TODO: handle possible overflow in 
>`steady_clock::now() + duration`.
>                 const bool timed_out = not 
>shared_queue().m_condition.wait_for(
>                     m_mutex_lock, duration, [&]() -> bool { return not 
>is_empty(); }
>                     );
>                 return not timed_out;
>             }
>
>             void enq( Item item, const bool notify = true )
>             {
>                 shared_queue().m_queue.push( move( item ) );
>                 m_n_notifications += notify;
>             }
>
>             auto deq() -> Item
>             {
>                 wait_for_items();
>                 hopefully( not is_empty() )
>                     or FSM_FAIL( "Waited for items but got none; 
>shared_queue is empty." );
>                 return popped_front_of( shared_queue().m_queue );
>             }
>         };
>
>         auto access() -> Access                 { return Access( *this ); }
>         auto access() const -> const Access     { return Access( *this ); }
>     };
>
>- Alf
>

[toc] | [prev] | [next] | [standalone]


#88999

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-06 23:44 +0100
Message-ID<trrvsn$385i5$1@dont-email.me>
In reply to#88996
On 2023-02-06 10:35 PM, Scott Lurndal wrote:
> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>> On 2023-02-05 10:39 PM, Alf P. Steinbach wrote:
>>> On 2023-02-05 9:49 PM, Chris M. Thomasson wrote:
>>>
>>>> Signalling a condition variable while the mutex is locked is not that
>>>> efficient unless the condvar has wait morphing. God, I have not
>>>> thought about wait morphing for a long time. Thanks for making me
>>>> think of it!
>>>
>>> Thanks. I don't know yet how to handle that with the RAII-based access
>>> scheme. Perhaps set a count of number of signals to issue then do that
>>> in the Access destructor.
>>
>> Implementation of that idea, hopefully it makes sense and is technically
>> correct:
> 
> Leaving aside the odd syntactic choices, what is the function
> of the class and why would it be of use?  How about providing
> an example of use?
> 
> I don't recall 'not', 'and' and 'or' being C++ keywords.

I do. ;-)

https://eel.is/c++draft/lex.digraph


> What's the difference between "mutex" and "Mutex_lock" types?

     using Mutex_lock = std::unique_lock<std::mutex>;

That is, a `Mutex_lock` is the combination of a lock and a mutex, as the 
name implies.

But now that you mention it, I realize the standard's terminology is not 
really clear. It should be a "locker", not a "lock". Yes.


> Where is the mutex actually acquired?  It is released in the
> destructor - does the undefined "Mutex_lock" class acquire the
> mutex in some misguided attempt to apply RAII to locking?

Yes it's RAII, and `std::unique_lock` is the standard library's RAII 
based wrapper for a mutex lock: it acquires a lock in its constructor.

I wouldn't call the standard library's threading support misguided.

Not because I know enough about the technical to evaluate it, but 
because I know that it's designed by some of the finest & best, and it 
worked fine for me.


> IME, a critical region generally protects more just queue accesses;
> it may also protect other data or make a certain code sequence atomic
> with respect to other threads.   That's one of the many reasons that
> I dislike the application of RAII to locking.
> 
> Whatever agent you used to post this wrapped many of the longer lines

The agent is Mozilla Thunderbird.

It uses a line continuation scheme that's specified in RFC 3676 section 
4.1, of putting a space at the end of a line as continuation symbol; 
<url: https://www.ietf.org/rfc/rfc3676.txt>.

That's called a "soft line break", and the scheme is called "flowed 
format", which you can see in the posting's headers.

Thus, looking at my posting in TB's usual view it's fine, but the raw 
posted text lines are wrapped.

Evidently your newsreader XRN (X news reader) or perhaps your version of 
that newsreader, doesn't support RFC 3676's flowed format.


> which made it even less readable than your nonstandard syntax choices.
> 
>       m_mutex.lock();
>       qe = m_queue.pop()
>       m_mutex_unlock();
> 
> seems to be much cleaner and far more readable (and thus more maintainable).

Yes, and in this case it would be sufficiently safe.

But in general it's not exception safe.

Letting a destructor do the unlocking is exception safe, and very 
convenient. :)


> The idea that locking can be solved using RAII universally is unviable.

That may be, I don't know enough yet to have an opinion. Sorry for being 
incompetent in this matter. :-o But it served its purpose well for the 
shared queue.


[snip code example]


- Alf

[toc] | [prev] | [next] | [standalone]


#89002

Fromscott@slp53.sl.home (Scott Lurndal)
Date2023-02-07 01:34 +0000
Message-ID<UUhEL.1040834$GNG9.712473@fx18.iad>
In reply to#88999
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>>> On 2023-02-05 10:39 PM, Alf P. Steinbach wrote:
>>>> On 2023-02-05 9:49 PM, Chris M. Thomasson wrote:
>
>That is, a `Mutex_lock` is the combination of a lock and a mutex, as the 
>name implies.
>
>But now that you mention it, I realize the standard's terminology is not 
>really clear. It should be a "locker", not a "lock". Yes.

>> Where is the mutex actually acquired?  It is released in the
>> destructor - does the undefined "Mutex_lock" class acquire the
>> mutex in some misguided attempt to apply RAII to locking?
>
>Yes it's RAII, and `std::unique_lock` is the standard library's RAII 
>based wrapper for a mutex lock: it acquires a lock in its constructor.
>
>I wouldn't call the standard library's threading support misguided.

Threading and synchronization are cooperative capabilities.  I was
specifically refering to using RAII for synchronization - while I was
brought up on pthreads, I certainly don't consider the standard
library's threading support 'misguided', nor did I say it was.

>
>Not because I know enough about the technical to evaluate it, but 
>because I know that it's designed by some of the finest & best, and it 
>worked fine for me.

I spent a decade on standards committees;  compromise is a key
to completing a standard rather than technical excellence (or elegance).

>
>
>> IME, a critical region generally protects more just queue accesses;
>> it may also protect other data or make a certain code sequence atomic
>> with respect to other threads.   That's one of the many reasons that
>> I dislike the application of RAII to locking.
>> 
>> Whatever agent you used to post this wrapped many of the longer lines
>
>The agent is Mozilla Thunderbird.
>
>It uses a line continuation scheme that's specified in RFC 3676 section 
>4.1, of putting a space at the end of a line as continuation symbol; 
><url: https://www.ietf.org/rfc/rfc3676.txt>.

Which, as you point out, is not supported by a thirty-plus year old
news reading client like xrn.   Personally, I prefer to see what I
wrote, rather than what someone somewhere thinks it should look like.

Someday I'll take the time to update it for UTF-8 and MIME support, multi-thread
it (a chore when using X11 libraries, the interactions with the display server
need to be isolated to a single thread), and add a local header cache.

Someday.

[toc] | [prev] | [next] | [standalone]


#89014

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-02-07 07:42 -0800
Message-ID<86ilgdcwis.fsf@linuxsc.com>
In reply to#88999
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:

> On 2023-02-06 10:35 PM, Scott Lurndal wrote:

[...]

>> Whatever agent you used to post this wrapped many of the longer lines
>
> The agent is Mozilla Thunderbird.
>
> It uses a line continuation scheme that's specified in RFC 3676
> section 4.1, of putting a space at the end of a line as continuation
> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>
> That's called a "soft line break", and the scheme is called "flowed
> format", which you can see in the posting's headers.
>
> Thus, looking at my posting in TB's usual view it's fine, but the raw
> posted text lines are wrapped.

Unfortunately some or many of those trailing spaces don't
survive getting to the client newsreader in the first place.
I've looked carefully.  In many cases where the lines are
wrapped, the trailing spaces aren't there.

> Evidently your newsreader XRN (X news reader) or perhaps your version
> of that newsreader, doesn't support RFC 3676's flowed format.

I've looked at the raw input, before it ever gets processed by
the newsreader.  On most of the wrapped lines, no trailing spaces.

[toc] | [prev] | [next] | [standalone]


#89016

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-07 17:34 +0100
Message-ID<trtuhp$3qciv$1@dont-email.me>
In reply to#89014
On 2023-02-07 4:42 PM, Tim Rentsch wrote:
> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
> 
>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
> 
> [...]
> 
>>> Whatever agent you used to post this wrapped many of the longer lines
>>
>> The agent is Mozilla Thunderbird.
>>
>> It uses a line continuation scheme that's specified in RFC 3676
>> section 4.1, of putting a space at the end of a line as continuation
>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>
>> That's called a "soft line break", and the scheme is called "flowed
>> format", which you can see in the posting's headers.
>>
>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>> posted text lines are wrapped.
> 
> Unfortunately some or many of those trailing spaces don't
> survive getting to the client newsreader in the first place.
> I've looked carefully.  In many cases where the lines are
> wrapped, the trailing spaces aren't there.
> 
>> Evidently your newsreader XRN (X news reader) or perhaps your version
>> of that newsreader, doesn't support RFC 3676's flowed format.
> 
> I've looked at the raw input, before it ever gets processed by
> the newsreader.  On most of the wrapped lines, no trailing spaces.

That's not what I see; furthermore without trailing spaces the articles 
would not be formatted correctly in Thunderbird's default view.

It may be a problem with the tool you use to inspect spaces 
(highlighting the text by selecting it is an easy way to see spaces), or 
it may be your newsreader.

I would guess that like Scott's XRN the Gnus 5.11, from 2007, may not 
support modern flowed format. There is however a later version, 5.14 
first released in 2013. But its a "development version", whatever that 
means. <url: https://en.wikipedia.org/wiki/Gnus>

- Alf

[toc] | [prev] | [next] | [standalone]


#89283

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-02-24 07:51 -0800
Message-ID<86fsavawos.fsf@linuxsc.com>
In reply to#89016
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:

> On 2023-02-07 4:42 PM, Tim Rentsch wrote:
>
>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>>
>>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>>
>> [...]
>>
>>>> Whatever agent you used to post this wrapped many of the longer lines
>>>
>>> The agent is Mozilla Thunderbird.
>>>
>>> It uses a line continuation scheme that's specified in RFC 3676
>>> section 4.1, of putting a space at the end of a line as continuation
>>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>>
>>> That's called a "soft line break", and the scheme is called "flowed
>>> format", which you can see in the posting's headers.
>>>
>>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>>> posted text lines are wrapped.
>>
>> Unfortunately some or many of those trailing spaces don't
>> survive getting to the client newsreader in the first place.
>> I've looked carefully.  In many cases where the lines are
>> wrapped, the trailing spaces aren't there.
>>
>>> Evidently your newsreader XRN (X news reader) or perhaps your version
>>> of that newsreader, doesn't support RFC 3676's flowed format.
>>
>> I've looked at the raw input, before it ever gets processed by
>> the newsreader.  On most of the wrapped lines, no trailing spaces.
>
> That's not what I see;  furthermore without trailing spaces the
> articles would not be formatted correctly in Thunderbird's default
> view.
>
> It may be a problem with the tool you use to inspect spaces
> (highlighting the text by selecting it is an easy way to see
> spaces), or it may be your newsreader.
>
> I would guess that like Scott's XRN the Gnus 5.11, from 2007, may
> not support modern flowed format.  There is however a later version,
> 5.14 first released in 2013.  But its a "development version",
> whatever that means.  <url: https://en.wikipedia.org/wiki/Gnus>

I think the newsgroup would be better served if, rather than
speculating about how other tools behave when you don't have any
facts, you would simply limit the line lengths of your postings
to 80 characters, as many coding standards and style guidelines
recommend.

[toc] | [prev] | [next] | [standalone]


#89302

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-02-24 18:48 +0100
Message-ID<ttat9j$29424$1@dont-email.me>
In reply to#89283
On 2023-02-24 4:51 PM, Tim Rentsch wrote:
> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
> 
>> On 2023-02-07 4:42 PM, Tim Rentsch wrote:
>>
>>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>>>
>>>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>>>
>>> [...]
>>>
>>>>> Whatever agent you used to post this wrapped many of the longer lines
>>>>
>>>> The agent is Mozilla Thunderbird.
>>>>
>>>> It uses a line continuation scheme that's specified in RFC 3676
>>>> section 4.1, of putting a space at the end of a line as continuation
>>>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>>>
>>>> That's called a "soft line break", and the scheme is called "flowed
>>>> format", which you can see in the posting's headers.
>>>>
>>>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>>>> posted text lines are wrapped.
>>>
>>> Unfortunately some or many of those trailing spaces don't
>>> survive getting to the client newsreader in the first place.
>>> I've looked carefully.  In many cases where the lines are
>>> wrapped, the trailing spaces aren't there.
>>>
>>>> Evidently your newsreader XRN (X news reader) or perhaps your version
>>>> of that newsreader, doesn't support RFC 3676's flowed format.
>>>
>>> I've looked at the raw input, before it ever gets processed by
>>> the newsreader.  On most of the wrapped lines, no trailing spaces.
>>
>> That's not what I see;  furthermore without trailing spaces the
>> articles would not be formatted correctly in Thunderbird's default
>> view.
>>
>> It may be a problem with the tool you use to inspect spaces
>> (highlighting the text by selecting it is an easy way to see
>> spaces), or it may be your newsreader.
>>
>> I would guess that like Scott's XRN the Gnus 5.11, from 2007, may
>> not support modern flowed format.  There is however a later version,
>> 5.14 first released in 2013.  But its a "development version",
>> whatever that means.  <url: https://en.wikipedia.org/wiki/Gnus>
> 
> I think the newsgroup would be better served if, rather than
> speculating about how other tools behave when you don't have any
> facts, you would simply limit the line lengths of your postings
> to 80 characters, as many coding standards and style guidelines
> recommend.

Even better, that you updated to more modern software. :-o

- Alf

[toc] | [prev] | [next] | [standalone]


#89319

FromDaniel <danielaparker@gmail.com>
Date2023-02-26 09:50 -0800
Message-ID<bf267305-6ad7-4f55-86b2-808eaeb4bf58n@googlegroups.com>
In reply to#89302
On Friday, February 24, 2023 at 12:48:51 PM UTC-5, Alf P. Steinbach wrote:
> On 2023-02-24 4:51 PM, Tim Rentsch wrote: 
> > I think the newsgroup would be better served if, rather than 
> > speculating about how other tools behave when you don't have any 
> > facts, you would simply limit the line lengths of your postings 
> > to 80 characters, as many coding standards and style guidelines 
> > recommend.
> Even better, that you updated to more modern software. :-o 
> 

I believe the first time that I've taken issue with Tim Rentsch, but,
yes :-)

Daniel

[toc] | [prev] | [next] | [standalone]


#89446

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-03-05 08:38 -0800
Message-ID<86v8jf887d.fsf@linuxsc.com>
In reply to#89319
Daniel <danielaparker@gmail.com> writes:

> On Friday, February 24, 2023 at 12:48:51?PM UTC-5, Alf P. Steinbach wrote:
>
>> On 2023-02-24 4:51 PM, Tim Rentsch wrote:
>>
>>> I think the newsgroup would be better served if, rather than
>>> speculating about how other tools behave when you don't have any
>>> facts, you would simply limit the line lengths of your postings
>>> to 80 characters, as many coding standards and style guidelines
>>> recommend.
>>
>> Even better, that you updated to more modern software. :-o
>
> I believe the first time that I've taken issue with Tim Rentsch, but,
> yes :-)

Note that my comment is not about tools but about matters of
visual presentation.  The tools I use have no problem dealing
with long lines but what tools do is not the high order bit here.
There are good human factors reasons to limit line length to
somewhere close to 80 characters, and that point is what I am
hoping to convey.

Note also that I am not the only newsgroup member, nor even the
first, to complain about Alf's idiosyncratic style choices.

[toc] | [prev] | [next] | [standalone]


#89447

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-03-05 08:43 -0800
Message-ID<86r0u387xy.fsf@linuxsc.com>
In reply to#89302
"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:

> On 2023-02-24 4:51 PM, Tim Rentsch wrote:

[...]

>> I think the newsgroup would be better served if, rather than
>> speculating about how other tools behave when you don't have any
>> facts, you would simply limit the line lengths of your postings
>> to 80 characters, as many coding standards and style guidelines
>> recommend.
>
> Even better, that you updated to more modern software. :-o

I'm sad to say that, coming from you, this statement doesn't
surprise me.  AFAIAA more people complain about problems your
tools cause than there are for the tools used in my postings.

[toc] | [prev] | [next] | [standalone]


#89478

From"Alf P. Steinbach" <alf.p.steinbach@gmail.com>
Date2023-03-06 15:51 +0100
Message-ID<tu4um8$1n67n$2@dont-email.me>
In reply to#89447
On 2023-03-05 5:43 PM, Tim Rentsch wrote:
> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
> 
>> On 2023-02-24 4:51 PM, Tim Rentsch wrote:
> 
> [...]
> 
>>> I think the newsgroup would be better served if, rather than
>>> speculating about how other tools behave when you don't have any
>>> facts, you would simply limit the line lengths of your postings
>>> to 80 characters, as many coding standards and style guidelines
>>> recommend.
>>
>> Even better, that you updated to more modern software. :-o
> 
> I'm sad to say that, coming from you, this statement doesn't
> surprise me.  AFAIAA more people complain about problems your
> tools cause than there are for the tools used in my postings.

Oh, people have failed to inform you that you're a dimwitted dipshit who 
presents fantasy as fact about any topic: technical, or people.

So, hereby done.

- Alf

[toc] | [prev] | [next] | [standalone]


#89017

Fromscott@slp53.sl.home (Scott Lurndal)
Date2023-02-07 16:35 +0000
Message-ID<P5vEL.624548$iU59.78651@fx14.iad>
In reply to#89014
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>"Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>
>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>
>[...]
>
>>> Whatever agent you used to post this wrapped many of the longer lines
>>
>> The agent is Mozilla Thunderbird.
>>
>> It uses a line continuation scheme that's specified in RFC 3676
>> section 4.1, of putting a space at the end of a line as continuation
>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>
>> That's called a "soft line break", and the scheme is called "flowed
>> format", which you can see in the posting's headers.
>>
>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>> posted text lines are wrapped.
>
>Unfortunately some or many of those trailing spaces don't
>survive getting to the client newsreader in the first place.
>I've looked carefully.  In many cases where the lines are
>wrapped, the trailing spaces aren't there.
>
>> Evidently your newsreader XRN (X news reader) or perhaps your version
>> of that newsreader, doesn't support RFC 3676's flowed format.
>
>I've looked at the raw input, before it ever gets processed by
>the newsreader.  On most of the wrapped lines, no trailing spaces.

XRN doesn't "process" the message, it simply displays it as is.

[toc] | [prev] | [next] | [standalone]


#89203

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-02-22 06:28 -0800
Message-ID<86sfexbwps.fsf@linuxsc.com>
In reply to#89017
scott@slp53.sl.home (Scott Lurndal) writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>>
>>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>>
>> [...]
>>
>>>> Whatever agent you used to post this wrapped many of the longer lines
>>>
>>> The agent is Mozilla Thunderbird.
>>>
>>> It uses a line continuation scheme that's specified in RFC 3676
>>> section 4.1, of putting a space at the end of a line as continuation
>>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>>
>>> That's called a "soft line break", and the scheme is called "flowed
>>> format", which you can see in the posting's headers.
>>>
>>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>>> posted text lines are wrapped.
>>
>> Unfortunately some or many of those trailing spaces don't
>> survive getting to the client newsreader in the first place.
>> I've looked carefully.  In many cases where the lines are
>> wrapped, the trailing spaces aren't there.
>>
>>> Evidently your newsreader XRN (X news reader) or perhaps your version
>>> of that newsreader, doesn't support RFC 3676's flowed format.
>>
>> I've looked at the raw input, before it ever gets processed by
>> the newsreader.  On most of the wrapped lines, no trailing spaces.
>
> XRN doesn't "process" the message, it simply displays it as is.

Surely displaying the message involves some processing,
even if not very much.

[toc] | [prev] | [next] | [standalone]


#89205

Fromscott@slp53.sl.home (Scott Lurndal)
Date2023-02-22 15:01 +0000
Message-ID<N6qJL.1183742$iU59.791145@fx14.iad>
In reply to#89203
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes:
>>>
>>>> On 2023-02-06 10:35 PM, Scott Lurndal wrote:
>>>
>>> [...]
>>>
>>>>> Whatever agent you used to post this wrapped many of the longer lines
>>>>
>>>> The agent is Mozilla Thunderbird.
>>>>
>>>> It uses a line continuation scheme that's specified in RFC 3676
>>>> section 4.1, of putting a space at the end of a line as continuation
>>>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>.
>>>>
>>>> That's called a "soft line break", and the scheme is called "flowed
>>>> format", which you can see in the posting's headers.
>>>>
>>>> Thus, looking at my posting in TB's usual view it's fine, but the raw
>>>> posted text lines are wrapped.
>>>
>>> Unfortunately some or many of those trailing spaces don't
>>> survive getting to the client newsreader in the first place.
>>> I've looked carefully.  In many cases where the lines are
>>> wrapped, the trailing spaces aren't there.
>>>
>>>> Evidently your newsreader XRN (X news reader) or perhaps your version
>>>> of that newsreader, doesn't support RFC 3676's flowed format.
>>>
>>> I've looked at the raw input, before it ever gets processed by
>>> the newsreader.  On most of the wrapped lines, no trailing spaces.
>>
>> XRN doesn't "process" the message, it simply displays it as is.
>
>Surely displaying the message involves some processing,
>even if not very much.

const char *source_pointer = source;
      char *dest_pointer = dest;

while (*source != '\0') *dest_pointer++ = *source_pointer++;

I would call that moving the data, not processing the data.

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.c++


csiph-web