addes threads
This commit is contained in:
parent
af93431a4b
commit
fccf397c64
BIN
src/routing4SITA
BIN
src/routing4SITA
Binary file not shown.
|
@ -1,8 +1,13 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "routing4SITA.h"
|
#include "routing4SITA.h"
|
||||||
|
|
||||||
|
|
||||||
|
void *Search(void* arguments);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("hello world!\n");
|
printf("hello world!\n");
|
||||||
|
|
||||||
|
@ -45,35 +50,106 @@ int main() {
|
||||||
b.nodescost[2] = 8;
|
b.nodescost[2] = 8;
|
||||||
|
|
||||||
NODE_t a;
|
NODE_t a;
|
||||||
b.id = 1;
|
a.id = 1;
|
||||||
b.nodescount = 2;
|
a.nodescount = 2;
|
||||||
b.nodesnext[0] = &c;
|
a.nodesnext[0] = &c;
|
||||||
b.nodescost[0] = 15;
|
a.nodescost[0] = 15;
|
||||||
b.nodesnext[1] = &d;
|
a.nodesnext[1] = &d;
|
||||||
b.nodescost[1] = 27;
|
a.nodescost[1] = 27;
|
||||||
|
|
||||||
NODE_t start;
|
NODE_t start;
|
||||||
b.id = 0;
|
start.id = 0;
|
||||||
b.nodescount = 2;
|
start.nodescount = 2;
|
||||||
b.nodesnext[0] = &a;
|
start.nodesnext[0] = &a;
|
||||||
b.nodescost[0] = 72;
|
start.nodescost[0] = 72;
|
||||||
b.nodesnext[1] = &b;
|
start.nodesnext[1] = &b;
|
||||||
b.nodescost[1] = 32;
|
start.nodescost[1] = 32;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pthread_t startThread;
|
||||||
|
|
||||||
|
THREAD_DATA_t* data;
|
||||||
|
|
||||||
|
data = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t));
|
||||||
|
|
||||||
|
data->node = &start;
|
||||||
|
data->cost = 0;
|
||||||
|
|
||||||
|
pthread_create(&startThread, NULL, Search, data);
|
||||||
|
|
||||||
|
//pthread_join(startThread,NULL);
|
||||||
|
|
||||||
|
for(;;){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *Search(void* arguments){
|
||||||
|
|
||||||
|
|
||||||
|
THREAD_DATA_t *data = (THREAD_DATA_t*) arguments;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("Number: %i\n", data->node->id);
|
||||||
|
printf("Cost to this node: %i\n", data->cost);
|
||||||
|
|
||||||
|
if(data->node->id == 8){
|
||||||
|
printf("End found! Cost: %i\ns", data->cost);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data->node->nodescount == 0){
|
||||||
|
printf("No next nodes\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_t threads[data->node->nodescount];
|
||||||
|
|
||||||
|
for(int i = 0; i < data->node->nodescount; i++){
|
||||||
|
|
||||||
|
THREAD_DATA_t* nextdata;
|
||||||
|
|
||||||
|
nextdata = (THREAD_DATA_t*) malloc(sizeof(THREAD_DATA_t));
|
||||||
|
|
||||||
|
nextdata->node = (data->node->nodesnext[i]);
|
||||||
|
|
||||||
|
nextdata->cost = data->node->nodescost[i] + data->cost;
|
||||||
|
|
||||||
|
//nextdata->cost = 42;
|
||||||
|
|
||||||
|
pthread_create(&threads[i], NULL, Search, nextdata);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
for(int i = 0; i < data->node->nodescount; i++) {
|
||||||
|
pthread_join(threads[i],NULL);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
|
|
||||||
typedef struct node NODE_t;
|
typedef struct node NODE_t;
|
||||||
|
typedef struct threadData THREAD_DATA_t;
|
||||||
|
|
||||||
struct node {
|
struct node {
|
||||||
int id;
|
int id;
|
||||||
|
@ -15,6 +16,12 @@ struct node {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct threadData {
|
||||||
|
NODE_t* node;
|
||||||
|
int cost;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue