14 #include <gtest/gtest.h> 32 if (m_func) (*m_func)();
else throw std::runtime_error(
"functor is NULL!!");
36 TAux(
void (*func)(
void) ) : terminated(false),m_func(func) {}
43 mrpt::system::createThreadFromObjectMethod<TAux>( &
obj, &
TAux::run, 0 );
48 while (!
obj.terminated && tim.Tac()<timeout_secs) {
52 if (!
obj.terminated) {
53 EXPECT_TRUE(
false) <<
"Thread didn't finished in timeout! While testing: " << fail_msg;
66 TEST(Synch, CriticalSections_Simple )
99 catch(std::exception &e)
101 cerr << e.what() << endl;
105 printf(
"[thread_example] Runtime error!\n");
113 for (
int i=1;i<=10;i++)
126 TEST(Synch, CriticalSections_Multi)
A namespace of pseudo-random numbers genrators of diferent distributions.
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
This class provides simple critical sections functionality.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
void my_CriticalSections_Simple()
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
void Tic()
Starts the stopwatch.
GLsizei GLsizei GLuint * obj
TThreadHandle createThread(void(*func)(T), T param)
Creates a new thread from a function (or static method) with one generic parameter.
void my_CriticalSections_Multi()
void leave() const MRPT_OVERRIDE
Leave.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
CCriticalSection csCounter
This class implements a high-performance stopwatch.
void enter() const MRPT_OVERRIDE
Enter.
This namespace provides multitask, synchronization utilities.
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void launchTestWithTimeout(void(*func)(void), double timeout_secs, const std::string &fail_msg)
void thread_example(int id)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
TEST(Synch, CriticalSections_Simple)