BSO BSO - 1 year ago 99
C Question

Shared memory between threads

I am looking for C program source code. Could you please help me in finding the source code required mentioned below.

program to create multiple threads (one master thread and rest worker threads) and using the threads write into and read from shared memory.

Answer Source

All the global variables are shared memory area for thread. 'x' is global and share among all threads in following example.

int sharedx=0;
void *threadFunc(void *arg)
    printf(" %d %s", sharedx,(char*)arg);
int main(void)
    pthread_t pth[10];  // this is our thread identifier
    int i = 0;
    for(i; i<10; i++) {