• Stars
    star
    1
  • Language
    C
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

You are required to write a C program to solve the following synchronization problem using POSIX and “semaphore.h” libraries. N mCounter threads count independent incoming messages in a system and another thread mMonitor gets the count of threads at time intervals of size t1, and then resets the counter to 0. The mMonitor then places this value in a buffer of size b, and a mCollector thread reads the values from the buffer. Any thread will have to wait if the counter is being locked by any other thread. Also, the mMonitor and mCollector threads will not be able to access the buffer at the same time or to add another entry if the buffer is full. Assume that the messages come randomly to the system, this can be realized if the mCounter threads sleep for random times, and their activation (sleep time ends) corresponds to an email arrival. Similarly, the mMonitor and mCollector will be activated at random time intervals.Breaking the problem down overview The problem statement may seem a little bit intimidating but once you divide the problem into smaller sub-problems; It'll become easier to approach. We have 3 types of threads mCounter , Monitor , and mCollector . At our main function, we should create one mMonitor thread, one mCollector thread but N mCounter threads. You should define N as a constant at the beginning of your code with any number you like 💡 5 to 10 threads are sufficient but you may decide to go higher or lower than that to test your code As mentioned above, to simulate messages coming randomly to the system we can let each mCounter thread sleep for a random period of time before it starts. Also, both the mCollector and mMonitor thread should be activated at random time intervals.Check srandom , random , and sleep . Dividing the problem It becomes much easier if we divided up the problem into two sub-problems Problem 1 Threads included: The N mCounter threads. The mMonitor thread. Shared resources: An integer to count messages. Problem: When a mCounter thread grants access to the counter, it should add one to it. When the mMonitor thread grants access to the counter, it should reset it to 0 and save its value to use it later. Only one thread should be able to access the shared counter.Problem 2 Threads included: The mMonitor thread. The mCollector thread. Shared resources: A buffer that should be implemented using a FIFO queue. Problem: It’s a bounded buffer producer/consumer problem. mMonitor is the producer. It enqueues the value that was saved from the previous problem into the buffer. mCollector is the consumer it takes the data out of the buffer.Program output The output shows the behavior of the threads. Each thread should print a certain output when a particular event happens: mCounter : At time of activation (sleep time end): Counter thread %I%: received a message Before waiting: Counter thread %I%: waiting to write After increasing the counter: Counter thread %I%: now adding to counter, counter value=%COUNTER% mMonitor : Before waiting to read the counter: Monitor thread: waiting to read counter After reading the counter value: Monitor thread: reading a count value of %COUNTER% After writing in the buffer: Monitor thread: writing to buffer at position %INDEX% If the buffer is full: Monitor thread: Buffer full!! mCollector : After reading from the buffer: Collector thread: reading from the buffer at position %INDEX% If the buffer is empty: Collector thread: nothing is in the buffer!

More Repositories

1

Simple-shell-implementation

It is required to implement a Unix shell program. Your shell must support the following: 1. The internal shell command "exit" which terminates the shell Concepts: shell commands, exiting the shell. System calls: exit() 2. A command with no arguments Example: ls …etc Details: Your shell must block until the command completes and, if the return code is abnormal, print out a message to that effect. Concepts: Forking a child process, waiting for it to complete and synchronous execution. System calls: fork() , execvp() , exit() , wait() 3. A command with arguments Example: ls –l, cp source destination, rm filename. Details: Argument 0 is the name of the command. Concepts: Command-line parameters 4. A command, with or without arguments, executed in the background using &. Example: firefox & Details: In this case, your shell must execute the command and return immediately, not blocking until the command finishes. Concepts: Background execution, signals, signal handlers, processes and asynchronous execution. Assignment 1 - Simple shell implementation 2 Requirements: You have to show that the opened process will be nested as a child process to the shell program via opening the task manager found in the operating system like in following figure. Additionally you have to write in a log file when a child process is terminated (main application will be interrupted by a SIGCHLD signal). So you have to implement an interrupt handler to handle this interrupt and do the corresponding action to it.To process the user command, do the following: 1. Your command shell should take the user command and its parameter(s), i.e., “ls” and “–l” in this example, and convert them into C strings. (Recall that a C string terminates with a null string, i.e., \0.) 2. The command shell should create a child process via fork() . Assignment 1 - Simple shell implementation 3 3. The child process passes the C strings—the command and parameter(s)—to execvp() . 4. The parent process, i.e., the command shell, should wait, via wait() , for the child process to finish. 5. The command shell gets the next command and repeats the above steps. The command shell terminates itself when the user types exit. In case a user wants to execute the command in background (i.e. as a background process), he/she writes & at the end of the command. For example, a user command can be: Shell > firefox & In this case, your command shell should not wait for the child by skipping the Step 4. You should keep a log file for your shell program such that whenever a child process terminates, the shell program appends the line “Child process was terminated” to the log file. To do this, you have to write a signal handler that appends the line to the log file when the SIGCHLD signal is received.
C
1
star
2

Car-Rental-System

Car Rental company asked you to implement a system with the following features:  The system should be able to register a new car (model, year, plate id, etc.) and update car status (active, out of service, etc.),  Customers will be able to reserve their cars from anywhere in the world via this system.  Customers provide information to this application by filling in their personal information to create an account and then he or she can reserve a car.  The proposed system effectively and efficiently automates manual procedures for car reservation (reserve, pick up, return, payment, etc.).  Customers are aided by your system to search the available cars by any of the car specs according to their needs.  System should be able to make advanced search which is searching by any of the car information, customer information or reservation day and get all information about the car, customer and reservation.  The system should provide the basic necessary reports (all reservations within a specified period including all car and customer information, all reservations of any car within a specified period including all car information, the status of all cars on a specific day, all reservations of specific customer including customer information, car model and plate id, and daily payments within specific period).
PHP
1
star