Initial commit

master
Denes Matetelki 14 years ago
commit 5bee45756d

@ -0,0 +1,22 @@
#ifndef MUTEX_HPP
#define MUTEX_HPP
#include <pthread.h>
class Mutex
{
public:
Mutex();
~Mutex();
void lock();
void unlock();
private:
pthread_mutex_t m_mutex;
};
#endif // MUTEX_HPP

@ -0,0 +1,26 @@
#include "Mutex.hpp"
Mutex::Mutex()
{
pthread_mutex_init( &m_mutex, 0 );
}
Mutex::~Mutex()
{
pthread_mutex_destroy ( &m_mutex );
}
void Mutex::lock()
{
pthread_mutex_lock( &m_mutex );
}
void Mutex::unlock()
{
pthread_mutex_unlock ( &m_mutex );
}

@ -0,0 +1,31 @@
#include <iostream>
#include <pthread.h>
#include "Mutex.hpp"
Mutex m;
int counter = 0;
void *functionC( void* params )
{
m.lock();
counter++;
std::cout << "Counter value: " << counter << std::endl;
m.unlock();
return 0;
}
int main()
{
pthread_t thread1, thread2;
pthread_create( &thread1, 0, &functionC, 0 );
pthread_create( &thread2, 0, &functionC, 0 );
pthread_join( thread1, 0 );
pthread_join( thread2, 0 );
return 0;
}
Loading…
Cancel
Save