Write a program to create a mmap() that is shared by multiple threads. Use fstat
ID: 3857666 • Letter: W
Question
Write a program to create a mmap() that is shared by multiple threads. Use fstat () to obtain the size of the mapped file to size the mapping. Find out the number of logical processors (or cores) available programmatically by calling sysconf(), as shown, and display this number. int numCPU = sysconf (_SC_NPROCESSORS_ ONLN): For this exercise, however, you are going to create four (4) threads only. Every thread should see the mapping. Each thread will display separate partial contents (sb.st_ size/4 bytes) of the file. Finally, unmap and close the file. Please make sure your code is working before answer this question. And also please show the command line to compile and the screenshots of the running code Please Do NOT answer this question with handwritten versionExplanation / Answer
#ifdef _WIN32 #include #elif MACOS #include #include #else #include #endif int getNumCores() { #ifdef WIN32 SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; #elif MACOS int nm[2]; size_t len = 4; uint32_t count; nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { nm[1] = HW_NCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { count = 1; } } return count; #else return sysconf(_SC_NPROCESSORS_ONLN); #endif }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.