I can't find anything wrong with my code. When i debug, this occurs.
Unhandled exception at 0x00fb74b1 in pacman.exe: 0xC0000005: Access violation reading location 0xfdfdfdfd.
printf("Lowest...
Type: Posts; User: erasm
I can't find anything wrong with my code. When i debug, this occurs.
Unhandled exception at 0x00fb74b1 in pacman.exe: 0xC0000005: Access violation reading location 0xfdfdfdfd.
printf("Lowest...
The semWait should suspend the producer thread until it is signaled by
get_buffer(). My semaphore's purpose is to protect buffer contents from being incorrectly overwritten and stop reading of an...
using i instead of random()
from put buffer = 0
from put buffer = 1
from put buffer = 2
from put buffer = 3
from put buffer = 4
from put buffer = 5
from put buffer = 6
from put buffer = 7
I am trying to follow this logic for a full buffer from a c++ tutorial and i can't see how my code is different. :(
From C++Course: Circular Buffer
if ((next + 1) % array.length == first)
...
The buffer should suspend when it is "full" and therefore not being overwritten by the last output block.
I can't see how this code isn't getting the output which should be:
buffer elem = -378931907
buffer elem = 1991142473
buffer elem = -2051466334
buffer elem = -1945167320
buffer elem =...
Why is this code getting a segmentation fault? how do i fix this?
void *producer(void* cb)
{
printf("testing\n");
bufferQueue *cbuffer = (bufferQueue *)cb;
...
semWait is defined in sema.c and the function prototype is in sema.h
sema.h
#include <pthread.h>
typedef struct semaphore
{
It's me again :)
When i compile i get this undefined reference to semWait
I don't know if the problem is with my make file or code.
Compiler:
gcc -lpthread -o pctest pctest.o circbuffer.o...
I have written a get_buffer function that will not allow the buffer to be read if the buffer is empty. However, i am having difficulty doing the logic for the requirement of disallowing the buffer to...
I am using a C++ tutorial as a reference on circular buffers and have a problem understanding the logic behind part of it.
Shouldn't remove() return an array excluding the oldest element in the...
Should i use max - min to allocate memory for the buffer array?
If so how would this be implemented, i am having difficulty getting my head around the manual for malloc :(
I would like to implement a dynamic array buffer_array for this tutorial. A hint for the tutorial suggests using malloc. How can malloc be used to implement this dynamic array for my tutorial?
...
Can this be done with only one semaphore initialized?
In order to test my semaphore i have used this implementation
So far the program will spawn a child which sleeps immediately and the parent reads buffer. Then when the child thread awakes it makes...
Now that i have written some semaphore functions i want to implement this program that used mutexes to achieve safe synchronization with these functions. But i am not sure how to approach this...
And the semSignal function:
void semSignal(semaphore *s)
{
pthread_mutex_lock(&(s->request_mutex));
if (s->count <= 0)
{
I am trying to implement the following algorithm as a semaphore. The semaphore struct will be passed as a parameter to semWait and semSigal.
- Are the mutexes responsible for protecting the...
Sorry i omitted some code.
I am having difficulty finding the race condition in this code. The tutorial i am doing indicates a semaphore implementation is needed to solve the race condition that cannot be solved by mutexes...
You missed a lock on m2 from the child thread.
//Parent
lock(m1)
lock(m2)
create_thread ()
fgets()
unlock(m1)
lock(m2)
printf()
Solved.
Swapped these around.
pthread_mutex_lock(&(d->mutex_a ));
pthread_mutex_lock(&(d->mutex_b ));
Why is this not printing the buffer? My understanding as commented in the code, is that once unlock is called on mutex_a in the parent, the suspended child should immediately begin executing which...
Sorry, i made an error in my post earlier, the tutorial asks to make the parent prompt the user after printing, not after the child is finished. I was using pthread_join to check this but now i need...
Thanks for the reply. Just a few more questions.
When you say the thread waits until the mutex is unlocked, do you mean the parent thread is waiting for the child thread to become unlocked?
...