Categories
Game Development

Wrote a worker thread class

Pretty useful and easy to use. You can cancel inputs before they are processed as well. #include “WorkerThreads.h” #include “RakSleep.h” #include #include void *func(void *input) { char *val = (char*) input; printf(“%s\n”, val); RakSleep(2000); return (void*)(val[strlen(val)-1]); } void main(void) { char *strings[9] = {“String 1”, “String 2”, “String 3”, “String 4”, “String 5”, “String 6”, […]

Pretty useful and easy to use. You can cancel inputs before they are processed as well.


#include "WorkerThreads.h"
#include "RakSleep.h"
#include
#include

void *func(void *input)
{
char *val = (char*) input;

printf("%s\n", val);
RakSleep(2000);
return (void*)(val[strlen(val)-1]);
}

void main(void)
{
char *strings[9] =
{"String 1",
"String 2",
"String 3",
"String 4",
"String 5",
"String 6",
"String 7",
"String 8",
"String 9"};

WorkerThreads workerThreads;
workerThreads.StartThreads(2, 0);
for (int i=0; i < 9; i++) { workerThreads.AddInput(func, strings[i]); } printf("Input sends done\n"); void *out; while(!kbhit()) { out=workerThreads.GetOutput(); if (out) { printf("Got output %i\n", (int) out); } } workerThreads.EndThreads(); }

Leave a Reply

Your email address will not be published. Required fields are marked *