13 #include <gtest/gtest.h> 53 cout <<
mrpt::format(
"[thread_example2 %i] Releasing..\n",
id);cout.flush();
57 catch(std::exception &e)
59 cerr << e.what() << endl;
63 printf(
"[thread_example2] Runtime error!\n");
67 template <
int num_threads,
int initial_sem_count>
70 std::vector<TThreadHandle> threads;
73 CSemaphore sem(initial_sem_count ,5*num_threads );
77 for (
int i=1;i<=num_threads;i++)
81 for (
size_t i=0;i<threads.size();i++)
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.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
unsigned long BASE_IMPEXP getCurrentThreadId() MRPT_NO_THROWS
Returns the ID of the current thread.
void launchTestWithTimeout(void(*func)(void), double timeout_secs, const std::string &fail_msg)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
TThreadHandle createThread(void(*func)(T), T param)
Creates a new thread from a function (or static method) with one generic parameter.
#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...
void sem_thread_example(int id)
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
This namespace provides multitask, synchronization utilities.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
A semaphore for inter-thread synchronization.
void BASE_IMPEXP joinThread(const TThreadHandle &threadHandle)
Waits until the given thread ends.