{"id":27993966,"url":"https://github.com/ahmeddwalid/osprogassign","last_synced_at":"2025-05-08T19:04:50.299Z","repository":{"id":271326315,"uuid":"913020711","full_name":"ahmeddwalid/OSProgAssign","owner":"ahmeddwalid","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-09T04:00:59.000Z","size":642,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T19:04:27.895Z","etag":null,"topics":["linux-shell","processes","systemcalls"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmeddwalid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-06T21:44:38.000Z","updated_at":"2025-01-19T01:07:02.000Z","dependencies_parsed_at":"2025-01-07T03:45:44.006Z","dependency_job_id":null,"html_url":"https://github.com/ahmeddwalid/OSProgAssign","commit_stats":null,"previous_names":["ahmeddwalid/osprogassign"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOSProgAssign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOSProgAssign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOSProgAssign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmeddwalid%2FOSProgAssign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmeddwalid","download_url":"https://codeload.github.com/ahmeddwalid/OSProgAssign/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253133134,"owners_count":21859111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux-shell","processes","systemcalls"],"created_at":"2025-05-08T19:04:49.583Z","updated_at":"2025-05-08T19:04:50.249Z","avatar_url":"https://github.com/ahmeddwalid.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 12th Programming Assignment\n\n\u003ch3 align=\"center\"\u003eAhmed Walid\u003c/h3\u003e\n\n---\n\n## Files Overview\n\n### 1. `task1-initial.c`\n\n#### **Description:**\n\n- Simulates a producer-consumer scenario without using explicit synchronization mechanisms like semaphores or mutexes.\n- Three threads perform the following tasks:\n  1. **Thread 1:** Creates an empty file.\n  2. **Thread 2 (Producer):** Generates random numbers and writes them to the file.\n  3. **Thread 3 (Consumer):** Reads numbers from the file.\n\n#### **Key Features:**\n\n- Demonstrates basic multithreading.\n- Uses file I/O for communication between producer and consumer.\n\n#### **Limitations:**\n\n- No synchronization, leading to potential race conditions (e.g., consumer reading before producer writes).\n\n---\n\n### 2. `task1-mutex.c`\n\n#### **Description:**\n\n- Extends `task1-initial.c` by adding synchronization using semaphores and mutexes to avoid race conditions.\n\n#### **Key Features:**\n\n- **Semaphores**:\n  - `empty`: Tracks empty slots in the buffer (file).\n  - `full`: Tracks full slots in the buffer (file).\n- **Mutex:** Ensures mutual exclusion during file access.\n\n#### **Improvements:**\n\n- Prevents consumer from reading before producer writes.\n- Handles concurrent access to shared resources more robustly.\n\n---\n\n### 3. `bonus-initial.c`\n\n#### **Description:**\n\n- Implements a multi-file producer-consumer scenario.\n- Three threads perform the following tasks:\n  1. **Thread 1:** Creates multiple empty files.\n  2. **Thread 2 (Producer):** Writes random numbers across the files, cycling between them.\n  3. **Thread 3 (Consumer):** Reads numbers from the files in a round-robin manner.\n\n#### **Key Features:**\n\n- Demonstrates advanced file handling with multiple producers and consumers.\n- Focuses on managing multiple files dynamically.\n\n#### **Limitations:**\n\n- No synchronization, making it prone to race conditions in concurrent environments.\n\n---\n\n### 4. `bonus-mutex.c`\n\n#### **Description:**\n\n- Builds upon `bonus-initial.c` by introducing synchronization to handle multiple files safely.\n\n#### **Key Features:**\n\n- **Semaphores:**\n  - `files_ready`: Signals when all files are created.\n  - `empty` and `full`: Manage buffer states across multiple files.\n- **Mutexes:**\n  - `file_mutex`: Protects file access.\n  - `count_mutex`: Protects global counters (e.g., numbers\\_written, numbers\\_read).\n\n#### **Improvements:**\n\n- Handles concurrency with proper synchronization.\n- Ensures correct order of operations between producers and consumers.\n\n---\n\n## Compilation and Execution\n\nEach program can be compiled and executed using GCC.\n\n### Compilation:\n\n```bash\ngcc -pthread -o output_file program_name.c\n```\n\n### Execution:\n\n```bash\n./output_file\n```\n\n---\n\n## Key Concepts Demonstrated\n\n### 1. **Multithreading with pthreads:**\n\n- Creation and management of threads using `pthread_create` and `pthread_join`.\n\n### 2. **Synchronization:**\n\n- Avoiding race conditions with semaphores (`sem_init`, `sem_wait`, `sem_post`) and mutexes (`pthread_mutex_lock`, `pthread_mutex_unlock`).\n\n### 3. **File I/O Operations:**\n\n- Writing to and reading from files in a multithreaded context.\n\n### 4. **Producer-Consumer Problem:**\n\n- Simulating real-world scenarios of producer-consumer workflows.\n\n---\n\n## Improvements and Customizations\n\n- **Error Handling:** Enhance error messages for better debugging.\n- **Dynamic File Handling:** Increase the number of files or lines dynamically based on input.\n- **Performance Optimization:** Optimize sleep intervals and buffer management for efficiency.\n- **Thread Scaling:** Extend programs to support multiple producers and consumers simultaneously.\n\n---\n\n## Author\n\nAhmed Walid\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmeddwalid%2Fosprogassign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmeddwalid%2Fosprogassign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmeddwalid%2Fosprogassign/lists"}