Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

This C program showcases multithreading and synchronization through POSIX threads (pthread) to compute the sum of square roots within a user-specified range.

License

Notifications You must be signed in to change notification settings

yigittuncer07/threads-experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded Sum Calculation Program

This C program demonstrates multithreading and synchronization using POSIX threads (pthread) to calculate the sum of square roots within a specified range.

Program Details

The program calculates the sum of square roots of numbers in a user-defined range using multiple threads. Three different methods are implemented for updating a global sum variable (global_sqrt_sum):

  1. Method 1 (d = 1): All threads update global_sqrt_sum concurrently without any critical sections. No mutex variables are used.

  2. Method 2 (d = 2): All threads update global_sqrt_sum serially. A single shared mutex variable is used to protect the updates.

  3. Method 3 (d = 3): Each thread uses a local variable (local_sqrt_sum) to calculate the sum of square roots. After local sums are calculated, each thread adds its local sum to global_sqrt_sum. A single shared mutex variable is used to protect the updates.

Usage

gcc -pthread -o project3.out project3.c -lm
./project3.out <a> <b> <num_threads> <method>

About

This C program showcases multithreading and synchronization through POSIX threads (pthread) to compute the sum of square roots within a user-specified range.

Topics

Resources

License

Stars

Watchers

Forks

Languages