title: In case of std::counting_semaphore, I am expecting undefined behaviour in below example. Please tell me whether my understanding is correct or not
body: <p>In below example thread t1 is calling release() and incrementing the
  counter by +1 which is fine but again thread t2 is calling release()
  and incrementing the counter by +1 which is not satisfying the
  precondition and going beyond max() value ie.1 so i am thinking that i
  am seeing such undefined behaviour because of this thing only.please tell me is my understanding correct or not?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;semaphore&gt;
  #include &lt;thread&gt;
  #include &lt;vector&gt;
  
  std::vector&lt;int&gt; myVec{};
  std::counting_semaphore&lt;1&gt; signal(0);              // (1)
  
  void addElement() 
  {
      std::cout &lt;&lt; &quot;In addElement() \n&quot;;
      myVec.insert(myVec.end(), {0, 1, 0, 3});
      std::cout &lt;&lt; &quot;Element added .&quot;  &lt;&lt; '\n';
      signal.release(); // (2)   
  }
  
  void accessElement() 
  {
      std::cout &lt;&lt; &quot;Waiting for data accessing.&quot; &lt;&lt; '\n';
      signal.acquire();// (3)
      std::cout &lt;&lt; &quot;updated the element.........&quot; &lt;&lt; '\n';
      for (auto i: myVec) 
          std::cout &lt;&lt; &quot;i :&quot; &lt;&lt; i &lt;&lt; &quot; &quot;;
      std::cout &lt;&lt; '\n';
      std::cout &lt;&lt; &quot;I am at end of accessElement()&quot; &lt;&lt; '\n';
  }
  
  int main() 
  {
      std::cout &lt;&lt; '\n';
      std::thread t1(addElement);
      std::thread t2(addElement);
      t1.join();
      t2.join();
      std::thread t3(accessElement);
      t3.join();
      std::cout &lt;&lt; '\n';
  }
  </code></pre>
  <p>output:</p>
  <pre><code>Program returned: 1 
  Program stderr
  
  =1==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x602000002010 in thread T0:   object passed to delete has wrong type: size of the allocated type:   16 bytes;   size of the deallocated type: -4080 bytes.
      #0 0x7f7507fc65b8 in operator delete(void*, unsigned long) (/opt/compiler-explorer/gcc-12.2.0/lib64/libasan.so.8+0xbd5b8)
      #1 0x406902 in std::__new_allocator&lt;int&gt;::deallocate(int*, unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/new_allocator.h:158
      #2 0x4058e9 in std::allocator&lt;int&gt;::deallocate(int*, unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/allocator.h:200
      #3 0x4058e9 in std::allocator_traits&lt;std::allocator&lt;int&gt; &gt;::deallocate(std::allocator&lt;int&gt;&amp;, int*, unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/alloc_traits.h:496
      #4 0x40428f in std::_Vector_base&lt;int, std::allocator&lt;int&gt; &gt;::_M_deallocate(int*, unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:387
      #5 0x403b9e in std::_Vector_base&lt;int, std::allocator&lt;int&gt; &gt;::~_Vector_base() /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:366
      #6 0x408253 in std::vector&lt;int, std::allocator&lt;int&gt; &gt;::~vector() /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:733
      #7 0x7f75079c58a6  (/lib/x86_64-linux-gnu/libc.so.6+0x468a6)
      #8 0x7f75079c5a5f in exit (/lib/x86_64-linux-gnu/libc.so.6+0x46a5f)
      #9 0x7f75079a3089 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24089)
      #10 0x4022ed in _start (/app/output.s+0x4022ed)
  
  0x602000002010 is located 0 bytes inside of 16-byte region [0x602000002010,0x602000002020) allocated by thread T2 here:
      #0 0x7f7507fc56b8 in operator new(unsigned long) (/opt/compiler-explorer/gcc-12.2.0/lib64/libasan.so.8+0xbc6b8)
      #1 0x40769b in std::__new_allocator&lt;int&gt;::allocate(unsigned long, void const*) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/new_allocator.h:137
      #2 0x4066e5 in std::allocator&lt;int&gt;::allocate(unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/allocator.h:188
      #3 0x4066e5 in std::allocator_traits&lt;std::allocator&lt;int&gt; &gt;::allocate(std::allocator&lt;int&gt;&amp;, unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/alloc_traits.h:464
      #4 0x405c47 in std::_Vector_base&lt;int, std::allocator&lt;int&gt; &gt;::_M_allocate(unsigned long) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:378
      #5 0x405039 in void std::vector&lt;int, std::allocator&lt;int&gt; &gt;::_M_range_insert&lt;int const*&gt;(__gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;, int const*, int const*, std::forward_iterator_tag) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/vector.tcc:787
      #6 0x403e1e in std::vector&lt;int, std::allocator&lt;int&gt; &gt;::insert(__gnu_cxx::__normal_iterator&lt;int const*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;, std::initializer_list&lt;int&gt;) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/stl_vector.h:1409
      #7 0x4025c4 in addElement() /app/example.cpp:12
      #8 0x408356 in void std::__invoke_impl&lt;void, void (*)()&gt;(std::__invoke_other, void (*&amp;&amp;)()) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/invoke.h:61
      #9 0x4082ee in std::__invoke_result&lt;void (*)()&gt;::type std::__invoke&lt;void (*)()&gt;(void (*&amp;&amp;)()) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/invoke.h:96
      #10 0x40829b in void std::thread::_Invoker&lt;std::tuple&lt;void (*)()&gt; &gt;::_M_invoke&lt;0ul&gt;(std::_Index_tuple&lt;0ul&gt;) /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/std_thread.h:252
      #11 0x40826f in std::thread::_Invoker&lt;std::tuple&lt;void (*)()&gt; &gt;::operator()() /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/std_thread.h:259
      #12 0x4081c5 in std::thread::_State_impl&lt;std::thread::_Invoker&lt;std::tuple&lt;void (*)()&gt;
  &gt; &gt;::_M_run() /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/std_thread.h:210
      #13 0x7f7507dc1a32  (/opt/compiler-explorer/gcc-12.2.0/lib64/libstdc++.so.6+0xe0a32)
  
  Thread T2 created by T0 here:
      #0 0x7f7507f56136 in pthread_create (/opt/compiler-explorer/gcc-12.2.0/lib64/libasan.so.8+0x4d136)
      #1 0x7f7507dc1d3b in std::thread::_M_start_thread(std::unique_ptr&lt;std::thread::_State, std::default_delete&lt;std::thread::_State&gt; &gt;, void (*)()) (/opt/compiler-explorer/gcc-12.2.0/lib64/libstdc++.so.6+0xe0d3b)
      #2 0x4029af in main /app/example.cpp:32
      #3 0x7f75079a3082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
  
  SUMMARY: AddressSanitizer: new-delete-type-mismatch (/opt/compiler-explorer/gcc-12.2.0/lib64/libasan.so.8+0xbd5b8) in operator delete(void*, unsigned long)
  ==1==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
  ==1==ABORTING x86-64 gcc 12.2 - cached
  </code></pre>