You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KED/oldDevFiles/temp/resources_lock/main.cpp

80 lines
1.2 KiB

#include <stdint.h>
#include <unistd.h>
#include <iostream>
#include <functional>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <cstdlib>
#include "resources.hpp"
Resources resources;
static void* task_1(void* arg)
{
int i = 0;
//for(i = 0; i < 10; i++) {
while(1) {
std::cout << std::endl << "Task 1 wanting to use resources"<< std::endl;
resources.print(1);//std::cout << "Hello, world!" << std::endl;
usleep(1000000);
}
while(1) usleep(10000);
};
static void* task_2(void* arg)
{
while(1)
{
std::cout << std::endl << "Task 2 wanting to use resources"<< std::endl;
resources.print(1000);
usleep(10000000);
}
};
int main(void)
{
pthread_t th_task_1;
pthread_t th_task_2;
int check = 0;
std::cout << "threads test" << std::endl;
check = pthread_create(&th_task_1,
NULL,
&task_1,
NULL);
if(check != 0) {
std::cout << "Failed to create thread!" << std::endl;
exit(-1);
}
check = pthread_create(&th_task_2,
NULL,
&task_2,
NULL);
if(check != 0) {
std::cout << "Failed to create thread!" << std::endl;
exit(-1);
}
pthread_join(th_task_1,NULL);
pthread_join(th_task_2,NULL);
return 0;
}