-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwf_queue_test.c
More file actions
88 lines (68 loc) · 1.76 KB
/
wf_queue_test.c
File metadata and controls
88 lines (68 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
*
*/
#include <pthread.h>
#include <stdlib.h>
#include "WaitFreeQueue.c"
struct pthread_start
{
int tid;
};
struct pthread_ret
{
int tid;
char* status;
};
WFQueue* q;
void* wf_queue_test(void* args)
{
struct pthread_start* pthread_arg = (struct pthread_start*)args;
int tid = pthread_arg->tid;
printf("tid: %i\n", tid);
queue_op_desc_t* op = (queue_op_desc_t*)atomic_load(
(atomic_intptr_t*)q->state[tid]);
printf("%i loaded: %lu with phase: %ld\n", tid, (long)op, op->phase);
printf("is_still_pending: %i\n", is_still_pending_test(q, tid, -1));
struct pthread_ret* ret = malloc(sizeof(struct pthread_ret));
ret->tid = tid;
ret->status = "SUCCESS!";
return (void*)ret;
wf_enqueue(q, tid, tid*5);
op = (queue_op_desc_t*)atomic_load(
(atomic_intptr_t*)q->state[tid]);
printf("%i loaded: %lu with phase: %ld\n", tid, (long)op, op->phase);
printf("is_still_pending: %i\n", is_still_pending_test(q, tid, 0));
return NULL;
}
int main()
{
printf("testing queue_op_desc_init\n");
queue_op_desc_t* p = queue_op_desc_init(-1, 0, 1, NULL);
printf("phase = %ld\n", p->phase);
printf("done testing queue_op_desc_init\n\n");
printf("About to initialize q\n");
q = wait_free_queue_init(3);
pthread_t** threads = calloc(3, sizeof(pthread_t));
for (int i = 0; i < 3; i++)
{
struct pthread_start* args = malloc(sizeof(struct pthread_start));
args->tid = i;
if (pthread_create(threads[i], NULL, &wf_queue_test, (void *)args))
{
printf("Created pthread\n");
}
free(args);
printf("got here\n");
}
for (int i = 0; i < 3; i++)
{
struct pthread_ret* ret;
pthread_join(*threads[i], (void*)&ret);
printf("%i: %s\n", ret->tid, ret->status);
free(ret);
}
printf("About to destroy q\n");
wait_free_queue_destroy(q);
free(threads);
exit(0);
}