Skip to content

Instantly share code, notes, and snippets.

View Karim-Monir's full-sized avatar
🎯
Focusing

Karim Monir Karim-Monir

🎯
Focusing
View GitHub Profile
@Karim-Monir
Karim-Monir / Peterson's Algorithm
Created January 18, 2022 02:37
This is an implementation of Peterson's Algorithm for two threads trying to access the same array with two different processes. one is to sort the array in ascending order, and the other one is sort the array is a descending order. Is this implementation right?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
#include <unistd.h>
//Sorting Ascending
void bubbleSortAsc(int array[], int size) {
for (int step = 0; step < size - 1; ++step) {