Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

linux c communication

$
0
0
Process (coordinator) process creates 10 jobs (pool of processes). Workflows waiting to be awakened by the coordinator perform a job and wait again. Coordinator transmits tag (integer) of the first process and wakes him up. The process adds one to bookmark and submit it to the next process, signaling that the coordinator. Coordinator wakes up the next process, which performs same actions etc. After going through all of marker processes coordinator visualize its content. For signaling processes to use signals to transmit marker to use shared memory.

i write like this but im not sure that is correct.sorry about my english.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

pthread_mutex_t m;
int global_marker = 0;

void* increment_globalMarker(void *arg){
	int i;
	int number_of_thread = *((int *)arg);
	
	for (i=0;i<100000; i++){
	if(ptrhread_mutex_trylock(&m) == 0)break;
	printf("\n Number of executed thread is: %d",number_of_thread);
	global_marker ++;
	pthread_mutex_unlock(&m);
	}
    pthread_exit(NULL);
}
int main(){
	int counter;
	pthread_t increment_thread[10];
	int thread_num[] = {0,1,2,3,4,5,6,7,8,9};
	
	printf("\n---THE INITIAL VALUE OF GLOBAL MARKER IS: %d",global_marker);

	pthread_mutex_init(&m, NULL);
	pthread_mutex_lock(&m);

	for(counter=0; counter<10; counter++){
	pthread_create(&increment_thread[counter], NULL, &increment_globalMarker, &thread_num[counter]);
	}
	pthread_join(increment_thread[0], NULL);
	pthread_join(increment_thread[1], NULL);
	pthread_join(increment_thread[2], NULL);
	pthread_join(increment_thread[3], NULL);
	pthread_join(increment_thread[4], NULL);
	pthread_join(increment_thread[5], NULL);
	pthread_join(increment_thread[6], NULL);
	pthread_join(increment_thread[7], NULL);
	pthread_join(increment_thread[8], NULL);
	pthread_join(increment_thread[9], NULL);

	pthread_mutex_destroy(&m);
	
	printf("\n THE END OF VALUE GLOBAL MARKERS %d",global_marker);
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>