this is an example of use of class libthreadar::thread
#include <libthreadar/libthreadar.hpp>
{
public:
my_thread() { synchro.lock(); };
void set_message(const std::string & msg)
{
message = msg;
};
void unlock_thread() { synchro.unlock(); };
void stop()
{
synchro.try_lock();
synchro.unlock();
synchro.try_lock();
}
protected:
{
while(1)
{
synchro.lock();
std::cout << message << std::endl;
}
}
private:
st::string message;
};
int main()
{
my_thread t1, t2;
t1.set_message("hello");
t2.set_message("world");
t1.run();
t2.run();
for(unsigned int i = 0; i < 20; ++i)
{
if(i % 2 == 0)
t1.unlock_thread();
if(i % 3 == 0)
t2.unlock_thread();
}
t1.stop();
t2.stop();
}
Exception used to report webdar internal bugs.
Wrapper around the Posix pthread_mutex_t C objects.
Class thread is a pure virtual class, that implements thread creation and operations.
bool is_running() const
checks whether a separated thread is running the inherited_run() method of this object
virtual void inherited_run()=0
action to be performed in the separated thread (implementation is expected in inherited classes)
void join() const
the caller will be suspended until the current object's thread ends