Libftpp
A modern C++ library
Thread Class Reference

Simple Thread Wrapper. More...

#include <thread.hpp>

Public Member Functions

 Thread (const std::string &name, std::function< void()> funcToExecute)
 
 ~Thread ()
 
void start ()
 
void stop ()
 

Detailed Description

Simple Thread Wrapper.

This class provides a simple wrapper around std::thread to manage a thread that executes a user-defined function. It includes basic start and stop functionality along with a thread-safe output stream for logging.

Note
Uses ThreadSafeIOStream for thread-safe logging
Thread myThread("MyThread", []() {
// Thread work here
for (int i = 0; i < 10; ++i) {
std::cout << "Thread iteration " << i << std::endl;
}
});
myThread.start();
// Do other work...
myThread.stop();
Simple Thread Wrapper.
Definition: thread.hpp:36
void start()
Definition: thread.cpp:13

Definition at line 35 of file thread.hpp.

Constructor & Destructor Documentation

◆ Thread()

Thread::Thread ( const std::string &  name,
std::function< void()>  funcToExecute 
)

Definition at line 7 of file thread.cpp.

References ThreadSafeIOStream::setPrefix().

◆ ~Thread()

Thread::~Thread ( )

Definition at line 3 of file thread.cpp.

References stop().

Member Function Documentation

◆ start()

void Thread::start ( )

Definition at line 13 of file thread.cpp.

References stop().

◆ stop()

void Thread::stop ( )

Definition at line 23 of file thread.cpp.

Referenced by start(), and ~Thread().