CODE :
#include<iostream>
#include<pthread.h>
#include<string>
using namespace std;
string animals[5] = {"dog", "cat","turkey","shark","lion"};
void *printWord(void *arg ){
int id = *((int*)arg);
cout<<"Current word : "<<animals[id] << endl;
pthread_exit(NULL);
}
int main(){
pthread_t thread_id[5];
for(int num = 0; num < 5; num++){
pthread_create(&thread_id[num],NULL,printWord,(void*)&num);
pthread_join(thread_id[num],NULL);
}
cout<<"Process done!\n";
return 0;
}
Output :

Explanation :
c++ Consider the following C++ code: 7 string animals[5] = {"dog", "cat", "turkey", "shark", "lion"); B...
I am getting the Segmentation fault error on the Ubuntu machine
but not on macOS.
Any help would be appreciated.
/**** main.c ****/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#define WORD_LEN 6
#define TOP 10
char * delim = "\"\'.“”‘’?:;-,—*($%)! \t\n\x0A\r";
struct Word {
char word[30];
int freq;
};
int threadCount;
int fileDescriptor;
int fileSize;
off_t chunk;
struct Word* wordArray;
int arrIndex = 0;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;...
C Programming - Please Help us! Implementing Load Balancing, the 3 Base Code files are at the bottom: Implementing Load Balancing Summary: In this homework, you will be implementing the main muti-threaded logic for doing batch based server load balancing using mutexes Background In this assignment you will write a batch-based load balancer. Consider a server which handles data proces- sing based on user requests. In general, a server has only a fixed set of hardware resources that it can...