The code is now going through the input successfully, but for some reason this isn't printing
fprintf(share->out, "Lift-%d Operation\r\n" "Previous position: Floor %d\r\n"
...
Type: Posts; User: Redsam121
The code is now going through the input successfully, but for some reason this isn't printing
fprintf(share->out, "Lift-%d Operation\r\n" "Previous position: Floor %d\r\n"
...
I'm now using virtualbox to test the code shmget is now working but shmat is giving permission denied.
So I changed shmget to const int shared_mem_id = shmget(IPC_PRIVATE, 2 * sizeof(sem_t),...
Is there any other option for windows 8
Error reports
E1: Function not implemented
E2: Invalid arguement
shared_mem_id is printing as -1. I'm using cygwin to test this code since I'm using windows.
I'm no longer getting those warnings on compiling. But the code just suddenly stops at sem_init(full, 1, 1);.
int shared_mem_id = shmget(IPC_PRIVATE, 2 * sizeof(sem_t), IPC_CREAT);//must...
Yes I am getting those errors. However the code now stops immediately at sem_init(full, 1, 1);.
By the way shouldn't full = &sems[0]; be full = &two_sems[0];?
I've been running diagnostics on it and I found that it doesn't return to lift-R when the buffer is empty and instead goes to lift-2 then lift-3. I'm positive it's to do with the sem mutexs.
...
When the buffer is full and calls sem_wait(&full); it goes into an infinite loop. I only want the while(1) to go until the sem_wait is called, then go to lift and return to request_t. It only stops...
Okay I've changed the size to (2 * sizeof(sem_t)) which should double the size for two semaphores. I've also changed void main to int main.
I've solved the buffer and share problem, but now having problems with the sem mutex. For example in request_t, even when wait is called, it continues in an infinite loop unless I add a break or...
I'm converting the program I wrote from the previous thread to use processes instead of threads. Since I got the pthread to work with the help of Salem, I don't need to worry about the looping...
Here is the latest update so far. It now goes through the file to the end, but once it's finished it becomes stuck in "Waiting for request" and only uses lift-1. Each lift should be used one at a...
I came up with a solution for (fscanf(((share_t*)vargp)->in, "%d %d\n", &A[in].from, &A[in].to) != EOF). I put it into an if statement and when it reaches the file, it'll break the while loop.
I tried using while (fscanf(((share_t*)vargp)->in, "%d %d\n", &A[in].from, &A[in].to) != EOF) before but that caused the lift write the wrong values to output. A value would be print before the...
All is forgiven, mistakes happen. So how do I stop the three lift threads from exiting until request thread is done?
But previously you said
>Another problem is both threads are writing to your output file in an unsafe way.
>request_t has a different mutex to lift.
So I removed one of the mutexes.
Also...
My latest update of the code. I've changed the error checking parameters and added an error check for argc. I've change the fprintfs to singluars, but haven't implemented sprintf. I've also changed...
So for the sprintf, it'd be something like sprintf(A[i].line, "New Lift Request from Floor %d to Floor %d \n", A[in_i].from, A[in_i].to); and then fprintf("%s", A[i].line);? Is my assumption correct?...
I solved the in and struct problems, they were printing properly but the crashing was causing the output file to blank. So they're fine.
I don't know if I arranged the pthread_join()s correctly...
I temporarily disabled mutex destroy, but the program still crashes after lift-3. I want it to return to lift-1 and keep going until the end of the text file.
The main problem is that it crashes after lift-3.
This is what I've got so far:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
#include "list.h"
I've changed mutex to only one lock. Both now have the same mutex. I'm now getting errors for fscanf on line 71. It's reporting too many arguements.
I implemented it but it caused the entire code crash on the third lift. Plus I don't think ((share_t*)vargp)->in will work anymore.
But a local pointer can't be shared globally and I need that space in pthread_creare for *out so I can print results to output.
Even if I did create a local pointer like int* id, what am I supposed...