Created
July 11, 2018 05:40
-
-
Save menangen/65a81e2e80d427e737d98d526f38e6bd to your computer and use it in GitHub Desktop.
POSIX threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// thread_test.c | |
// testingSwift & C with SPM | |
// | |
// Created by menangen on 11.07.18. | |
// Copyright (c) 2018 menangen. All rights reserved. | |
// | |
#import <stdio.h> | |
#import <stdlib.h> | |
#import <pthread.h> | |
#define NUM_OF_THREADS 4 | |
struct perlinData | |
{ | |
int x; | |
}; | |
void *processArray(void* arg) | |
{ | |
struct perlinData* me = (struct perlinData*)arg; | |
//printf("..Get int in address: %p \n", arg); | |
printf("-> Spawn thread %i \n", me->x); | |
pthread_exit(NULL); | |
} | |
unsigned char main() { | |
pthread_t threads[NUM_OF_THREADS]; | |
for (int i = 0; i < NUM_OF_THREADS; i++) { | |
struct perlinData* me = malloc( sizeof(struct perlinData) ); | |
me->x = 1 + i; | |
//printf("[Allocate] data in address: %p \n", me); | |
//printf("x = %i\n", me->x); | |
pthread_create(&threads[i], NULL, processArray, me); | |
printf("[Creating] %i thread \n", i); | |
} | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment