Mercurial > hg > CbC > old > CbC_scripts
changeset 15:ea6c94f9840a
add synchronizedQueueIdeal
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Oct 2015 16:13:17 +0900 |
parents | af04833f7667 |
children | f748d295b08f |
files | meta_connector/meta_connect_test.c meta_connector/meta_connect_test_name.c meta_connector/meta_connector.py meta_connector/meta_connector_name.py meta_connector/synchronizedQueueIdeal.c |
diffstat | 5 files changed, 504 insertions(+), 322 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/meta_connector/meta_connect_test.c Fri Oct 16 16:13:17 2015 +0900 @@ -0,0 +1,226 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "synchronizedQueueContext.h" + +#include "allocate.h" +#include "origin_cs.h" + +#ifdef CLANG +#define _CbC_retrun __return +#define _CbC_environment __environment +#endif + +#define NUM 100 + +extern __code initSynchronizedQueueContext(struct Context* context); + +//__code code1(struct Context* context) { +// context->data[Allocate]->allocate.size = sizeof(struct Element); +// context->data[Allocate]->allocate.next = Code2; +// goto meta(context, Allocator); +//} + +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +//__code code2(struct Context* context) { +// context->data[Allocate]->allocate.after_put = Code3; +// context->data[context->dataNum] -> element.value = 1024; +// goto meta(context, Sender); +//} + +__code code1(struct Allocate* allocate) { + allocate->size = sizeof(long); + allocate->next = Code2; + goto allocator(); +} + +__code code1_stub(struct Context* context) { + goto code1(context, &context->data[Allocate]->allocate); +} + +__code code2(long* count) { + *count = 0; + goto meta(context, Code3); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &context->data[Counter]->count); +} + +__code code3(long* count, struct Allocate* allocate) { + long loop = *count; + if(loop == NUM) { + goto meta(context, ThreadExit); + } + allocate->size = sizeof(struct Element); + allocate->next = Code4; + goto meta(context, Allocator); +} + +__code code3_stub(struct Context* context) { + goto code3(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); +} + +__code code4(long* count, struct Allocate* allocate, struct Element* element) { + allocate->after_put = Code3; + element->value = (*count)++; + goto meta(context, Sender); +} + +__code code4_stub(struct Context* context) { + goto code4(context, &context->data[Counter]->count, &context->data[Allocate]->allocate, &context->data[context->dataNum]->element); +} + +__code meta_sender(struct Context* context, struct Queue* queue, enum Code next) { + // lock + pthread_mutex_lock(&queue->mutex); + goto (context->code[next])(context); +} + +__code sender(struct Queue* queue) { + // goto meta_sender(context, queue, Put); + goto put(queue); +} + +__code sender_stub(struct Context* context) { + goto sender(context, &context->data[Queue]->queue); +} + +__code meta_put(struct Context* context, struct Queue* queue, enum Code next) { + // signal + pthread_cond_signal(&queue->cond); + // unlock + pthread_mutex_unlock(&queue->mutex); + goto (context->code[next])(context); +} + +__code put(struct Allocate* allocate, struct Queue* queue, struct Element* element) { + if(queue->first) { + queue->last->next = element; + } else { + queue->first = element; + } + queue->last = element; + element->next = 0; + queue->count++; + printf("Put %d\n\n", element->value); + goto meta_put(context, queue, allocate->after_put); +} + +__code put_stub(struct Context* context) { + goto put(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[context->dataNum]->element); +} + +__code code5(struct Allocate* allocate) { + allocate->size = sizeof(long); + allocate->next = Code6; + goto meta(context, Allocator); +} + +__code code5_stub(struct Context* context) { + goto code5(context, &context->data[Allocate]->allocate); +} + +__code code6(long* count) { + *count = 0; + goto meta(context, Code7); +} + +__code code6_stub(struct Context* context) { + goto code6(context, &context->data[Counter]->count); +} + +__code code7(long* count, struct Allocate* allocate) { + long loop = *count; + if(loop == NUM) { + goto meta(context, ThreadExit); + } + (*count)++; + allocate->after_get = Code7; + goto meta(context, Receiver); +} + +__code code7_stub(struct Context* context) { + goto code7(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); +} + +__code meta_receiver(struct Context* context, struct Queue* queue, enum Code next) { + // lock + pthread_mutex_lock(&queue->mutex); + goto (context->code[next])(context); +} + +__code receiver(struct Queue* queue) { + // goto meta_receiver(context, queue, Get); + goto get(queue); +} + +__code receiver_stub(struct Context* context) { + goto receiver(context, &context->data[Queue]->queue); +} +__code meta_get(struct Context* context, enum Code next) { + pthread_mutex_unlock(&context->data[Queue]->queue.mutex); + goto (context->code[next])(context); +} + +__code get(struct Allocate* allocate, struct Queue* queue, struct Element* element) { + // thread wait if queue is empty + while (queue->count == 0) { + pthread_cond_wait(&queue->cond, &queue->mutex); + } + printf(" Get %d\n\n", queue->first->value); + queue->first = (queue->first->next) ? queue->first->next : 0; + queue->count--; + goto meta_get(context, allocate->after_get); +} + +__code get_stub(struct Context* context) { + goto get(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[context->dataNum]->element); +} + +__code thread_exit(struct Context* context) { + free(context->code); + free(context->data); + free(context->heapStart); + pthread_exit(0); +} + +__code thread_exit_stub(struct Context* context) { + goto thread_exit(context); +} + +void* thread_func(void* context) { + goto start_code((struct Context*)context, Code1); + return 0; +} + +void* thread_func2(void* context) { + goto start_code((struct Context*)context, Code5); + return 0; +} + +int main() { + struct Context* context1 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context1); + struct Context* context2 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context2); + struct Context* context3 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context3); + struct Context* context4 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context4); + context2->data[Queue] = context1->data[Queue]; + context3->data[Queue] = context1->data[Queue]; + context4->data[Queue] = context1->data[Queue]; + pthread_t thread1, thread2, thread3, thread4; + pthread_create(&thread1, NULL, thread_func, (void *)context1); + pthread_create(&thread2, NULL, thread_func, (void *)context2); + pthread_create(&thread3, NULL, thread_func2, (void *)context3); + pthread_create(&thread4, NULL, thread_func2, (void *)context4); + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + pthread_join(thread3, NULL); + pthread_join(thread4, NULL); +}
--- a/meta_connector/meta_connect_test_name.c Tue Oct 06 18:49:20 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,226 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> - -#include "synchronizedQueueContext.h" - -#include "allocate.h" -#include "origin_cs.h" - -#ifdef CLANG -#define _CbC_retrun __return -#define _CbC_environment __environment -#endif - -#define NUM 100 - -extern __code initSynchronizedQueueContext(struct Context* context); - -//__code code1(struct Context* context) { -// context->data[Allocate]->allocate.size = sizeof(struct Element); -// context->data[Allocate]->allocate.next = Code2; -// goto meta(context, Allocator); -//} - -__code meta(struct Context* context, enum Code next) { - goto (context->code[next])(context); -} - -//__code code2(struct Context* context) { -// context->data[Allocate]->allocate.after_put = Code3; -// context->data[context->dataNum] -> element.value = 1024; -// goto meta(context, Sender); -//} - -__code code1(struct Allocate* allocate) { - allocate->size = sizeof(long); - allocate->next = Code2; - goto allocator(); -} - -__code code1_stub(struct Context* context) { - goto code1(context, &context->data[Allocate]->allocate); -} - -__code code2(long* count) { - *count = 0; - goto meta(context, Code3); -} - -__code code2_stub(struct Context* context) { - goto code2(context, &context->data[Counter]->count); -} - -__code code3(long* count, struct Allocate* allocate) { - long loop = *count; - if(loop == NUM) { - goto meta(context, ThreadExit); - } - allocate->size = sizeof(struct Element); - allocate->next = Code4; - goto meta(context, Allocator); -} - -__code code3_stub(struct Context* context) { - goto code3(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); -} - -__code code4(long* count, struct Allocate* allocate, struct Element* element) { - allocate->after_put = Code3; - element->value = (*count)++; - goto meta(context, Sender); -} - -__code code4_stub(struct Context* context) { - goto code4(context, &context->data[Counter]->count, &context->data[Allocate]->allocate, &context->data[context->dataNum]->element); -} - -__code meta_sender(struct Context* context, struct Queue* queue, enum Code next) { - // lock - pthread_mutex_lock(&queue->mutex); - goto (context->code[next])(context); -} - -__code sender(struct Queue* queue) { - // goto meta_sender(context, queue, Put); - goto put(queue); -} - -__code sender_stub(struct Context* context) { - goto sender(context, &context->data[Queue]->queue); -} - -__code meta_put(struct Context* context, struct Queue* queue, enum Code next) { - // signal - pthread_cond_signal(&queue->cond); - // unlock - pthread_mutex_unlock(&queue->mutex); - goto (context->code[next])(context); -} - -__code put(struct Allocate* allocate, struct Queue* queue, struct Element* element) { - if(queue->first) { - queue->last->next = element; - } else { - queue->first = element; - } - queue->last = element; - element->next = 0; - queue->count++; - printf("Put %d\n\n", element->value); - goto meta_put(context, queue, allocate->after_put); -} - -__code put_stub(struct Context* context) { - goto put(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[context->dataNum]->element); -} - -__code code5(struct Allocate* allocate) { - allocate->size = sizeof(long); - allocate->next = Code6; - goto meta(context, Allocator); -} - -__code code5_stub(struct Context* context) { - goto code5(context, &context->data[Allocate]->allocate); -} - -__code code6(long* count) { - *count = 0; - goto meta(context, Code7); -} - -__code code6_stub(struct Context* context) { - goto code6(context, &context->data[Counter]->count); -} - -__code code7(long* count, struct Allocate* allocate) { - long loop = *count; - if(loop == NUM) { - goto meta(context, ThreadExit); - } - (*count)++; - allocate->after_get = Code7; - goto meta(context, Receiver); -} - -__code code7_stub(struct Context* context) { - goto code7(context, &context->data[Counter]->count, &context->data[Allocate]->allocate); -} - -__code meta_receiver(struct Context* context, struct Queue* queue, enum Code next) { - // lock - pthread_mutex_lock(&queue->mutex); - goto (context->code[next])(context); -} - -__code receiver(struct Queue* queue) { - // goto meta_receiver(context, queue, Get); - goto get(queue); -} - -__code receiver_stub(struct Context* context) { - goto receiver(context, &context->data[Queue]->queue); -} -__code meta_get(struct Context* context, enum Code next) { - pthread_mutex_unlock(&context->data[Queue]->queue.mutex); - goto (context->code[next])(context); -} - -__code get(struct Allocate* allocate, struct Queue* queue, struct Element* element) { - // thread wait if queue is empty - while (queue->count == 0) { - pthread_cond_wait(&queue->cond, &queue->mutex); - } - printf(" Get %d\n\n", queue->first->value); - queue->first = (queue->first->next) ? queue->first->next : 0; - queue->count--; - goto meta_get(context, allocate->after_get); -} - -__code get_stub(struct Context* context) { - goto get(context, &context->data[Allocate]->allocate, &context->data[Queue]->queue, &context->data[context->dataNum]->element); -} - -__code thread_exit(struct Context* context) { - free(context->code); - free(context->data); - free(context->heapStart); - pthread_exit(0); -} - -__code thread_exit_stub(struct Context* context) { - goto thread_exit(context); -} - -void* thread_func(void* context) { - goto start_code((struct Context*)context, Code1); - return 0; -} - -void* thread_func2(void* context) { - goto start_code((struct Context*)context, Code5); - return 0; -} - -int main() { - struct Context* context1 = (struct Context*)malloc(sizeof(struct Context)); - initSynchronizedQueueContext(context1); - struct Context* context2 = (struct Context*)malloc(sizeof(struct Context)); - initSynchronizedQueueContext(context2); - struct Context* context3 = (struct Context*)malloc(sizeof(struct Context)); - initSynchronizedQueueContext(context3); - struct Context* context4 = (struct Context*)malloc(sizeof(struct Context)); - initSynchronizedQueueContext(context4); - context2->data[Queue] = context1->data[Queue]; - context3->data[Queue] = context1->data[Queue]; - context4->data[Queue] = context1->data[Queue]; - pthread_t thread1, thread2, thread3, thread4; - pthread_create(&thread1, NULL, thread_func, (void *)context1); - pthread_create(&thread2, NULL, thread_func, (void *)context2); - pthread_create(&thread3, NULL, thread_func2, (void *)context3); - pthread_create(&thread4, NULL, thread_func2, (void *)context4); - pthread_join(thread1, NULL); - pthread_join(thread2, NULL); - pthread_join(thread3, NULL); - pthread_join(thread4, NULL); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/meta_connector/meta_connector.py Fri Oct 16 16:13:17 2015 +0900 @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +import argparse +import re + +# parse arguments and return arguments list. +def get_args(): + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description="""\ +Parse meta connect syntax. Default output is stdout. + +sample) +__code code0(struct Data data1, ...){ + goto code1(data1, data2, ...); + \t| + \tV +__code code0(struct Context* context, struct Data data1, ...){ + goto meta_code1(context, data1, data2, ..., Code1); + """) + parser.add_argument('input_file',\ + nargs=None,\ + type=str,\ + help='input file path.') + parser.add_argument('-o', dest='output',\ + nargs=1,\ + type=str,\ + metavar='<file>',\ + help='write output to <file>') + + return parser.parse_args() + +# parse input file and create meta connection list +def parse_meta_syntax(lines,file): + comment_out = False + target_cs = False + caller_name = '' + isMetaOrStub = False + for i,l in enumerate(lines): + + regexed_l = re.search(r"[a-zA-Z0-9_]+ *\(",l) + + # get caller code segment name + if re.search(r"^ *__code",l) is not None: + caller_name = regexed_l.group(0).rstrip('(') + if re.search(r"^ *meta_*|stub$",caller_name) is not None: + isMetaOrStub = True + file.write(l) + else: + isMetaOrStub = False + splited = l.split('(',1) + file.write("/*-- generated by script */\n") + file.write('// '+l) + file.write('{0:s}(struct Context* context, {1:s}'.format(splited[0],splited[1])) + elif not isMetaOrStub and regexed_l is not None and re.search(r"^ *goto",l): + callee_name = regexed_l.group(0).rstrip('(') + if re.match('meta_|meta$',callee_name): + file.write(l) + else: + file.write("/*-- connected by script */\n") + file.write('// '+l) + args = l.split('(')[1].rsplit(')')[0].strip() + args = args + ',' if args else '' + meta_name = 'meta_'+caller_name if meta_search(lines, callee_name) else 'meta' + file.write("goto {0:s}(context, {1:s} {2:s});\n".format(meta_name, args,\ + callee_name.capitalize())) + else: + file.write(l) + +# search meta code segment. +# Find it : __code meta_'name' +def meta_search(lines, name): + for l in lines: + if re.search(r"^ *__code +meta_{0:s}\(".format(name),l) is not None: + return True + return False + +def main(): + args = get_args() + output = sys.stdout + try: + f = open(args.input_file,'r') + except IOError: + print("cannot open file %s" % input_file) + if args.output is not None: + try: + output = open(args.output[0],'w') + except IOError: + print("cannot open file %s" % args.output) + + lines = f.readlines() + connect_list = parse_meta_syntax(lines, output) + +main()
--- a/meta_connector/meta_connector_name.py Tue Oct 06 18:49:20 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import sys -import argparse -import re - -# parse arguments and return arguments list. -def get_args(): - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description="""\ -Parse meta connect syntax. Default output is stdout. - -sample) -__code code0(struct Data data1, ...){ - goto code1(data1, data2, ...); - \t| - \tV -__code code0(struct Context* context, struct Data data1, ...){ - goto meta_code1(context, data1, data2, ..., Code1); - """) - parser.add_argument('input_file',\ - nargs=None,\ - type=str,\ - help='input file path.') - parser.add_argument('-o', dest='output',\ - nargs=1,\ - type=str,\ - metavar='<file>',\ - help='write output to <file>') - - return parser.parse_args() - -# parse input file and create meta connection list -def parse_meta_syntax(lines,file): - comment_out = False - target_cs = False - caller_name = '' - isMetaOrStub = False - for i,l in enumerate(lines): - - regexed_l = re.search(r"[a-zA-Z0-9_]+ *\(",l) - - # get caller code segment name - if re.search(r"^ *__code",l) is not None: - caller_name = regexed_l.group(0).rstrip('(') - if re.search(r"^ *meta_*|stub$",caller_name) is not None: - isMetaOrStub = True - file.write(l) - else: - isMetaOrStub = False - splited = l.split('(',1) - file.write("/*-- generated by script */\n") - file.write('// '+l) - file.write('{0:s}(struct Context* context, {1:s}'.format(splited[0],splited[1])) - elif not isMetaOrStub and regexed_l is not None and re.search(r"^ *goto",l): - callee_name = regexed_l.group(0).rstrip('(') - if re.match('meta_|meta$',callee_name): - file.write(l) - else: - file.write("/*-- connected by script */\n") - file.write('// '+l) - args = l.split('(')[1].rsplit(')')[0].strip() - args = args + ',' if args else '' - meta_name = 'meta_'+caller_name if meta_search(lines, callee_name) else 'meta' - file.write("goto {0:s}(context, {1:s} {2:s});\n".format(meta_name, args,\ - callee_name.capitalize())) - else: - file.write(l) - -# search meta code segment. -# Find it : __code meta_'name' -def meta_search(lines, name): - for l in lines: - if re.search(r"^ *__code +meta_{0:s}\(".format(name),l) is not None: - return True - return False - -def main(): - args = get_args() - output = sys.stdout - try: - f = open(args.input_file,'r') - except IOError: - print("cannot open file %s" % input_file) - if args.output is not None: - try: - output = open(args.output[0],'w') - except IOError: - print("cannot open file %s" % args.output) - - lines = f.readlines() - connect_list = parse_meta_syntax(lines, output) - -main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/meta_connector/synchronizedQueueIdeal.c Fri Oct 16 16:13:17 2015 +0900 @@ -0,0 +1,182 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "synchronizedQueueContext.h" + +#include "allocate.h" +#include "origin_cs.h" + +#ifdef CLANG +#define _CbC_retrun __return +#define _CbC_environment __environment +#endif + +#define NUM 100 + +extern __code initSynchronizedQueueContext(struct Context* context); +extern void allocator(struct Context* context); + +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +//__code code1(struct Context* context) { +// context->data[Allocate]->allocate.size = sizeof(struct Element); +// goto code2(context); +//} + +__code code1(struct Context* context, struct Allocate* allocate) { + allocate->size = sizeof(long); + allocator(context); + long* count = &context->data[Counter]->count + goto code2(count) +} + +__code code2(struct Context* context, long* count) { + *count = 0; + struct Allocate* allocate = &context->data[Allocate]->allocate; + goto code3(count, allocate); +} + +__code code3(struct Context* context, long* count, struct Allocate* allocate) { + long loop = *count; + if(loop == NUM) { + goto thread_exit(); + } + allocate->size = sizeof(struct Element); + allocator(context); + struct Element* element = &context->data[context->dataNum]->element) + got code4(count, allocate, element); +} + +__code code4(struct Context* context, long* count, struct Allocate* allocate, struct Element* element) { + allocate->after_put = Code3; + element->value = (*count)++; + struct Queue* queue = &context->data[Queue]->queue; + goto sender(queue); +} + +__code meta_sender(struct Context* context, struct Queue* queue, enum Code next) { + // lock + pthread_mutex_lock(&queue->mutex); + goto (context->code[next])(context); +} + +__code sender(struct Context* context, struct Queue* queue) { + goto meta_sender(context, queue, Put); +} + +__code meta_put(struct Context* context, struct Queue* queue, enum Code next) { + // signal + pthread_cond_signal(&queue->cond); + // unlock + pthread_mutex_unlock(&queue->mutex); + goto (context->code[next])(context); +} + +__code put(struct Context* context, struct Allocate* allocate, struct Queue* queue, struct Element* element) { + if(queue->first) { + queue->last->next = element; + } else { + queue->first = element; + } + queue->last = element; + element->next = 0; + queue->count++; + printf("Put %d\n\n", element->value); + goto meta_put(context, queue, allocate->after_put); +} + +__code code5(struct Context* context, struct Allocate* allocate) { + allocate->size = sizeof(long); + allocator(context); + long* count = &context->data[Counter]->count + goto code6(count); +} + +__code code5_stub(struct Context* context) { + goto code5(context, &context->data[Allocate]->allocate); +} + +__code code6(struct Context* context, long* count) { + *count = 0; + struct Allocate* allocate = &context->data[Allocate]->allocate; + goto code7(count, allocate); +} + +__code code7(struct Context* context, long* count, struct Allocate* allocate) { + long loop = *count; + if(loop == NUM) { + goto meta(context, ThreadExit); + } + (*count)++; + allocate->after_get = Code7; + struct Queue* queue = &context->data[Queue]->queue; + goto receiver(queue); +} + +__code meta_receiver(struct Context* context, struct Queue* queue, enum Code next) { + // lock + pthread_mutex_lock(&queue->mutex); + goto (context->code[next])(context); +} + +__code receiver(struct Context* context, struct Queue* queue) { + goto meta_receiver(context, queue, Get); +} + +__code meta_get(struct Context* context, enum Code next) { + pthread_mutex_unlock(&context->data[Queue]->queue.mutex); + goto (context->code[next])(context); +} + +__code get(struct Context* context, struct Allocate* allocate, struct Queue* queue, struct Element* element) { + // thread wait if queue is empty + while (queue->count == 0) { + pthread_cond_wait(&queue->cond, &queue->mutex); + } + printf(" Get %d\n\n", queue->first->value); + queue->first = (queue->first->next) ? queue->first->next : 0; + queue->count--; + goto meta_get(context, allocate->after_get); +} + +__code thread_exit(struct Context* context) { + free(context->code); + free(context->data); + free(context->heapStart); + pthread_exit(0); +} + +void* thread_func(void* context) { + goto start_code((struct Context*)context, Code1); + return 0; +} + +void* thread_func2(void* context) { + goto start_code((struct Context*)context, Code5); + return 0; +} + +int main() { + struct Context* context1 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context1); + struct Context* context2 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context2); + struct Context* context3 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context3); + struct Context* context4 = (struct Context*)malloc(sizeof(struct Context)); + initSynchronizedQueueContext(context4); + context2->data[Queue] = context1->data[Queue]; + context3->data[Queue] = context1->data[Queue]; + context4->data[Queue] = context1->data[Queue]; + pthread_t thread1, thread2, thread3, thread4; + pthread_create(&thread1, NULL, thread_func, (void *)context1); + pthread_create(&thread2, NULL, thread_func, (void *)context2); + pthread_create(&thread3, NULL, thread_func2, (void *)context3); + pthread_create(&thread4, NULL, thread_func2, (void *)context4); + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + pthread_join(thread3, NULL); + pthread_join(thread4, NULL); +}