Compare commits

...

2 Commits

Author SHA1 Message Date
552f95fe99 A5 as it was submitted 2023-11-02 23:53:29 -03:00
e0a1232987 Finish a5 as much as it can be 2023-11-02 23:51:50 -03:00
4 changed files with 41 additions and 1 deletions

View File

@ -4,4 +4,5 @@
4. The print thread will wait on the sim sem for each CPU thread, and this should leave the sem at 0 again. 4. The print thread will wait on the sim sem for each CPU thread, and this should leave the sem at 0 again.
5. At the end of the print function, before the simulation is allowed to print again, the print thread will increase the time, and then post to the sim sem for each CPU thread, so the simulation can start again. 5. At the end of the print function, before the simulation is allowed to print again, the print thread will increase the time, and then post to the sim sem for each CPU thread, so the simulation can start again.
6. Repeat steps 3-5 until the simulation is done. 6. Repeat steps 3-5 until the simulation is done.
7.
This is the general process, at least at the time I wrote this down lmao

23
Assignment5/README.md Normal file
View File

@ -0,0 +1,23 @@
# How to run
To compile please run:
```shell
gcc -Ilib lib/process.c lib/queue.c hard_affinity.c
```
And to run please run:
```shell
./a.out < example.txt
```
# In case of error
If that command to compile does not work, please place all C and C header files in the same directory and run:
```shell
gcc process.c queue.c hard_affinity.c
```
In case you need to move the files, for easy copying:
```shell
mv lib/process.c . & mv lib/queue.c . & mv lib/queue.h . & mv lib/process.h .
```

View File

@ -4,6 +4,22 @@
#include <stdlib.h> #include <stdlib.h>
#include "lib/queue.h" #include "lib/queue.h"
/*
* Marker, please read:
*
* There is a bug that I cannot track down/may be unsolvable with my current implementation.
* It's where *sometimes* the print function, after a thread finishes, it will print an extra time on one job (I think)
*
* This could probably be solved by running the "done threads" until all threads are complete, but I didn't have time to bugfix that
* implementation. I tried it, but it didn't work as is, so I reverted it.
*
* With that implementation it may have been beneficial to have an array of semaphores, one for each "CPU", that the print thread
* can for loop wait on each to complete. I think that would have worked, but I straight up didn't have time to implement it or try at all
*
* The comments may also not be the most helpful, didn't have time to go and clean them up
*/
#define MAX_USERNAME_LENGTH 100 #define MAX_USERNAME_LENGTH 100
int *QUANTUM; int *QUANTUM;
int CPUS; int CPUS;

Binary file not shown.