Zadania rekrutacyjne i ćwiczeniowe
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.
 
 

36 lines
641 B

#include "thread/QueuedThread.h"
#include "thread/Blocker.h"
#include <stdio.h>
#include <unistd.h>
static const int COUNT = 3;
static const int SLEEP_US = 200*1000;
void task(void* arg);
int main() {
QueuedThread* thread = createQueuedThread();
postQueuedTask(thread, &task, NULL);
postQueuedTask(thread, &task, NULL);
for (int i = 0; i < COUNT*2+1; i++) {
printf("Main: %d\n", i);
usleep(SLEEP_US);
}
joinQueuedThread(thread);
freeQueuedThread(&thread);
return 0;
}
// ---
void task(void* arg) {
(void)arg;
for (int i = 0; i < COUNT; i++) {
printf("Thread: %d\n", i);
usleep(SLEEP_US);
}
}