C++ Threads


#include <thread>
#include <mutex>
#include <atomic>

std::thread    t(thread_function);

std::thread::hardware_concurrency()
std::thread::get_id()
std::this_thread::get_id();

t.join();
t.detach();
t.joinable();
t.get_id();

static std::mutex               m;
std::lock_guard<std::mutex>     guard(m);
std::unique_lock<std::mutex>    l(m);
std::atomic<int>                result(0);
std::condition_variable         condvar;

m.lock();
m.unlock();
condvar.wait(...);
condvar.notify_one();

  • Function Pointer
  • Function Objects
  • Lambda functions

C++11 multithreading tutorial
C++11 multithreading tutorial – part 2
C++11 Multithreading – Part 1 : Three Different ways to Create Threads
C++11/C++14 Thread 1. Creating Threads

Posts about C++11 Concurrency Tutorial
C++11 Concurrency – Part 1 : Start Threads
C++11 Concurrency Tutorial – Part 2 : Protect shared data
C++11 Concurrency Tutorial – Part 3: Advanced locking and condition variables

C++ Copy Elision and Return Value Optimization

  • RVO = Return Value Optimization
  • NRVO = Named Return Value Optimization
  • Copy Constructor (ctor)
  • Copy Assignment Operator
  • Move Constructor (ctor): C::C(C&& other);
  • Move Assignment Operator: C& C::operator=(C&& other);
  • Move Semantics
  • Temporary
  • Lvalue: object that occupies some identifiable location in memory (i.e. has an address)
  • Rvalue: temporary register (i.e. has NOT address)
  • Rvalue References: std::string&& rrstr;
  • Lvalue references: std::string& ref;
  • Reference Variables

Understanding lvalues and rvalues in C and C++

Six User-Declared Special Member Functions

  • Default constructor
  • Copy constructor (ctor)
  • Copy assignment operator
  • Move Constructor (ctor)
  • Move Assignment Operator
  • Destructor

C++ declares its remaining special member functions implicitly, if there are no user-declared functions.

Vokabular

  • pilfer = stehlen, entwenden, klauen, stibitzen
  • elision = Weglassung, Auslassung

Hitherto, copying has been the only means for transferring a state from one object to another.
And yet, in many real-world scenarios, you don’t copy objects but move them.
Notwithstanding the conceptual difference between copying and moving, there’s a practical difference too: Move operations tend to be faster than copying because they transfer an existing resource to a new destination, whereas copying requires the creation of a new resource from scratch.

Bislang war das Kopieren das einzige Mittel, um einen Zustand von einem Objekt auf ein anderes zu übertragen.
Doch in vielen realen Szenarien kopiert man Objekte nicht, sondern verschiebt sie.
Ungeachtet des konzeptionellen Unterschieds zwischen Kopieren und Verschieben gibt es auch einen praktischen Unterschied: Verschiebeoperationen sind tendenziell schneller als Kopieren, weil sie eine bestehende Ressource an ein neues Ziel übertragen, während beim Kopieren eine neue Ressource von Grund auf neu erstellt werden muss.

Übersetzt mit www.DeepL.com/Translator (kostenlose Version)

Is there any gorgeous way for C++ to return an object without copying it in memory?
Returning a c++ std::vector without a copy?
What are copy elision and return value optimization?
Move or Named Return Value Optimization (NRVO)?
What Is RVO And NRVO In C++? (YouTube Video)

C++11 Tutorial: Introducing the Move Constructor and the Move Assignment Operator

cppreference.com

Copy elision
Move constructors

Schalter / Wechselschalter / Umschalter

Schalter
Wechselschalter
SPDT

“FOCUS ON” – Switches Explained! (PDF)
Grundlegende Funktionsweise von Stromkreisen

Was ist der Unterschied zwischen Schalter /Taster/ Tastschalter?

Abkürzung des Schalters Beschreibung
SPST Das Kürzel SPST bezeichnet einen einpoligen Schalter, der entweder offen oder geschlossen ist.
SPDT Die Abkürzung SPDT bedeutet, dass dieser einpolige Schalter eine Zusatzfunktion des Wechselschalters beinhaltet. Dies bedeutet, dass der Schalter entweder Gerät 1 oder 2 verbindet.
SPTT / SPCO Hier handelt es sich um die Erweiterung des SPDT durch einen Nullpunkt. Es müssen nicht unbedingt Gerät 1 oder 2 geschaltet werden, es kann auch eine Nullstellung gewählt sein.
DPST Das Kürzel steht für zwei einpolige Schalter. Durch dieses Modell ist es möglich gleich zwei Stromkreise zu schließen.
DPDT Das Kürzel steht für zwei einpolige Schalter. Durch dieses Modell ist es möglich gleich zwei Stromkreise zu schließen.
DPCO Das ist die Erweiterung des DPDT durch die Nullstellung.

Raspberry Pi 3, rpi-update

Es gibt so gut wie keinen Grund an einem laufenden System ein Firmware- und Kernel-Update mit “rpi-update” durchzuführen. Die Gefahr ist viel zu groß, dass danach das eine oder andere System nicht mehr richtig funktioniert.”

Ein Update über “rpi-update” kann “unstable” sein. Das heißt, dass daran noch entwickelt wird und dass es vielleicht fehlerhaft ist. Sobald Firmware, Bootloader, der Kernel und die Bibliotheken “stable” sind, werden sie über “apt-get upgrade” verfügbar gemacht und sind dann offiziell installierbar.

Deshalb generell die Empfehlung, Finger weg von “rpi-update“. Es sei denn man weiß, warum man das tut.

github.com/Hexxeh/rpi-update, An easier way to update the firmware of your Raspberry Pi
Firmware- und Kernel-Update mit rpi-update beim Raspberry Pi

Raspberry Pi 3, Power Requirements

FAQ: WHAT ARE THE POWER REQUIREMENTS?

Voltage

“Power sources SHOULD provide 5±0.25V”
“The newer Pi(3/2/B+) have a voltage monitor chip (APX803) which triggers at 4.63±0.07V. This controls the Red Power LED.”

Low Power

“China Power Supplies: They may appear to work OK for a lightly loaded Pi, but may not if many peripherals are connected.”
“If you use poor quality cables to connect to the Pi you will have problems.”

Current

“The Pi 3.3V rail is widely assumed to provide 50mA, but this is not officially documented for recent Pi models.”
“The regulator chip (which supplies both 3.3V and 1.8V) is rated at 1A.”
“Tests by a member indicate up to 800mA can be used – subject to an adequate power supply.”

Raspberry Pi Power Limitations

Feasability Of Powering A Raspberry Pi With A 3.7V Battery