How do I pass a matrix as an argument between two function that are in different source files? (with their respective header file)
Do not worry about all the variables and arguments below.
//uex1010.cpp
typedef int Casilla;
void ejecutar(){
int tamanio, maxPuntos, numPiezas,puntActual=0;
int fila, col, color, ancho, alto;//variables
bool salir;
fila=0;
col=0;
TipoTecla tecla;
srand(time(NULL));
if (entornoCargarConfiguracion(tamanio, maxPuntos, numPiezas)) {
entornoIniciar(tamanio);
}
int i;
entornoActivarCasilla(fila, col);
salir = false;
Casilla ocupada[tamanio-1][tamanio-1];
comprobarCasilla(ocupada[tamanio-1][tamanio-1],col,fila,alto,ancho,color,tamanio);// I want to send "ocupada" to comprobarCasilla() in tablero.cpp
//............
tablero.cpp
void comprobarCasilla(Casilla &ocupada, int col, int fila, int &alto, int &ancho, int &color, int tamanio) {
int i = 0, j = 0, colaux = col, filaux = fila;
while ((i < alto) && (ocupada[fila][col] == 0)) {//HERE
col = colaux;
j = 0;
while ((j < ancho) && (ocupada[fila][col]==0)) {//HERE
col++;
j++;
}
fila++;
i++;
}
if (ocupada[fila][col]==0) {//AND HERE it returns an error
pintar(ocupada, colaux, filaux, alto, ancho, color);
}
}
The error is: tipos inválidos ‘Casilla {aka bool}[int]’ para índice de matriz
invalid types ‘Casilla {aka bool}[int]’ for matrix index
Here is the header file:
#ifndef TABLERO_H_
#define TABLERO_H_
#include "entorno.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "pieza.h"
typedef int Casilla;
void iniciarTablero(bool salir);
void pintar(Casilla ocupada,int col,int fila,int &alto,int &ancho,int &color);
void comprobarCasilla(Casilla &ocupada,int col,int fila,int &alto,int &ancho,int &color,int tamanio);
#endif /* TABLERO_H_ */
Related
I am new at using Google Mock and I encountered an error: "Error: Actual function call count doesn't match EXPECT_CALL(…)".
I am not sure what I am doing incorrectly. I followed this solution suggested here and I am still encountering this error.
Here is the sample code I am working on:
Orig Class
//orig.h
#include <stdio.h>
class Orig {
public:
virtual ~Orig(){}
virtual int this_func(uint8_t x, uint8_t* y, uint8_t z) = 0;
virtual int that_func(uint8_t x, uint8_t* y, uint8_t z) = 0;
virtual void those_func(int abc) = 0;
};
Mock Orig Class
//mock_orig.h
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "calling_class.h"
class MockOrig : public Orig {
public:
MOCK_METHOD3(this_func, int(uint8_t x, uint8_t* y, uint8_t z));
MOCK_METHOD3(that_func, int(uint8_t x, uint8_t* y, uint8_t z));
MOCK_METHOD1(those_func, void(int abc));
};
Calling Class
//calling_class.h
#define MY_CONST1 0x01
#define MY_CONST2 0x02
#define X_CONST1 0x03
#define X_CONST2 0x04
#define SAMPLE_VALUE (20)
#define TOTAL_VALUE (100/SAMPLE_VALUE)
#include "orig.h"
class CallingClass {
public:
explicit CallingClass(Orig * o) : mOrig(o){};
void calling_func(void) {
static int oldValue = 0;
static uint16_t counter = 0;
uint8_t buffer[2] = {0};
int firstBit = 0;
int secondBit = 0;
if (0 == oldValue && (0 == mOrig->this_func(X_CONST1, buffer, 1))
{
secondBit = (int)(buffer[0] & MY_CONST2);
firstBit = (int)(buffer[0] & MY_CONST1);
if((oldValue != secondBit) && (0 != firstBit))
{
mOrig->those_func(secondBit);
oldValue = secondBit;
counter = TOTAL_VALUE;
}
return;
}
if (0 >= --counter && (0 == mOrig->this_func(X_CONST1, buffer, 1)))
{
uint8_t out = buffer[0] | MY_CONST2;
mOrig->that_func(X_CONST2, &out, 1);
oldValue = 0;
}
return;
}
private:
Orig * mOrig;
}
Test Proper
//mock_orig.cpp
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <memory>
TEST(myTest, testMyFunction)
{
std::shared_ptr<Orig> mO(new MockOrig);
uint8_t buffer[1];
EXPECT_CALL(*std::static_pointer_cast<MockOrig>(mO), this_func(X_CONST1, buffer, 1))
.Times(1);
CallingClass callerClass(mO.get());
callerClass.calling_func();
}
int main(int argc, char **argv)
{
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
Can somebody please tell me what is still wrong with this? Any help/leads would be greatly appreciated. thanks!
I am trying to call a cuda function that is defined in a cu file from a cpp file in Visual Studio but I keep receiving the following error.
TomColourCorrectionMain.obj : error LNK2019: unresolved external symbol "public: void __cdecl hwk::TomColourCorrection::brightness(int,int)" (?brightness#TomColourCorrection#hwk##QEAAXHH#Z) referenced in function "public: virtual void __cdecl hwk::TomColourCorrection::processCore(class std::shared_ptr)" (?processCore#TomColourCorrection#hwk##UEAAXV?$shared_ptr#VIImageProcessingContext#hwk###std###Z)
Now from reading other questions similar to this, I understand its to do with how the function is defined and that there is something wrong there but I can't see it from when I have defined in the header and cuda file.
This is the code I have (I am a novice at CUDA but I can compile CUDA fine and the code runs when I don't call this function in C++):
header file
#pragma once
#include "ImageProcessorWithProperties.h"
#include <iostream>
#include <cuda_runtime.h>
#include <cuda.h>
class TomColourCorrection : public ImageProcessorWithProperties, public PropertyConsumer<TomColourCorrection>{
public: TomColourCorrection(PropNodePtr n, std::function<void()> requestReprocess);
virtual void processCore(IImageProcessingContextPtr context);
static void DeclareSettings(hwk::PropNodePtr n);
virtual ~TomColourCorrection();
void brightness(int iw, int ih); (function I am talking about)
};
}
cpp file with function call //its just segments of the important code as the rest of it isn't necessary for the actual function itself
#include "stdafx.h"
#include "TomColourCorrection.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <cuda_runtime.h>
#include <cuda.h>
namespace hwk{
TomColourCorrection::TomColourCorrection(PropNodePtr n, std::function<void()> requestReprocess) :
ImageProcessorWithProperties("sandbox", n, requestReprocess),
PropertyConsumer<TomColourCorrection>(n)
{
}
void TomColourCorrection::processCore(IImageProcessingContextPtr context){
brightness(16, 16); (just generic numbers at the moment as I am trying to resolve this issue etc)
}
}
CUDA File and function definition
#include "TomColourCorrection.h"
#include "device_launch_parameters.h"
__global__ void brightness_kernel(int iw, int ih)
{
// Calculate our pixel's location
int x = (blockIdx.x * blockDim.x) + threadIdx.x;
int y = (blockIdx.y * blockDim.y) + threadIdx.y;
// Variables to store the sum
int count = 0;
float sum = 0.0;
// Do the blur operation by summing the surround pixels
/* for (int j = -(bh / 2); j <= (bh / 2); j++)
{
for (int i = -(bw / 2); i <= (bw / 2); i++)
{
// Verify that this offset is within the image boundaries
if ((x + i) < iw && (x + i) >= 0 && (y + j) < ih && (y + j) >= 0)
{
sum += (float)source[((y + j) * iw) + (x + i)];
count++;
}
}
}*/
// Average the sum
sum /= (float)count;
// dest[(y * iw) + x] = (unsigned char)sum;
}
void brightness(int iw, int ih) //, unsigned char *source, unsigned char *dest)
{
// allocate memory for the bitmap in GPU memory
unsigned char *dev_source, *dev_dest;
// cudaHostGetDevicePointer(&dev_source, source, 0);
// cudaHostGetDevicePointer(&dev_dest, dest, 0);
// Run the boxfilter kernel
dim3 blocks(iw / 16, ih / 16);
dim3 threads(16, 16);
// Execute the kernel
brightness_kernel << <blocks, threads >> >(iw, ih);
cudaThreadSynchronize();
}
Modify the TomColourCorrection.h like this:
#pragma once
#include "ImageProcessorWithProperties.h"
#include <iostream>
#include <cuda_runtime.h>
#include <cuda.h>
void brightness_wrapper(int, int);
class TomColourCorrection : public ImageProcessorWithProperties, public PropertyConsumer<TomColourCorrection>{
public:
TomColourCorrection(PropNodePtr n, std::function<void()> requestReprocess);
virtual void processCore(IImageProcessingContextPtr context);
static void DeclareSettings(hwk::PropNodePtr n);
virtual ~TomColourCorrection();
void brightness(int iw, int ih);
};
Modify your cpp file like this:
#include "stdafx.h"
#include "TomColourCorrection.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <cv.h>
#include <highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <cuda_runtime.h>
#include <cuda.h>
namespace hwk{
void TomColourCorrection::brightness(int iw, int ih){
brightness_wrapper(iw, ih);}
TomColourCorrection::TomColourCorrection(PropNodePtr n, std::function<void()> requestReprocess) : ImageProcessorWithProperties("sandbox", n, requestReprocess), PropertyConsumer<TomColourCorrection>(n)
{
}
void TomColourCorrection::processCore(IImageProcessingContextPtr context){
brightness(16, 16);
}
}
And in your cuda file change this:
void brightness(int iw, int ih) //, unsigned char *source, unsigned char *dest)
to this:
void brightness_wrapper(int iw, int ih) //, unsigned char *source, unsigned char *dest)
This is mainly just spelling out the details of Ryck's answer.
I think you need change
void brightness(int iw, int ih)
to
void TomColourCorrection::brightness(int iw, int ih)
and move the implementation to your header file or a .cpp file.
I am putting both the CPP and HPP files here and the error I receive:
I am adding the complete code here and the error I am encountering; kindly help.
Kindly help me in posting this question too.
CPP:
#include "TimeWindowCounter.hpp"
#include <iostream>
#include "../../Common/TimeAnalyser.hpp"
TimeWindowCounter::TimeWindowCounter()
{
init();
}
void TimeWindowCounter::init()
{
boost::atomic<bool> first_order_sent(false);
}
TimeWindowCounter::TimeWindowCounter(double currTime)
{
first_order_sent = true;
startTime = currTime;
endTime = currTime;
orderCount = 0;
ind = 0;
N = 1000;
for (int j =0; j<= 99; j++ )
numberofOrder[j] = 0;
}
TimeWindowCounter::~TimeWindowCounter()
{
}
void TimeWindowCounter::addOrder()
{
orderCount++;
numberofOrder[ind] = orderCount;
}
void TimeWindowCounter::clockTick(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t, int* count, double* currTime)
{
stopTime = *currTime;
WindowSize = timeAnalyser.getDiffTime_rt(startTime, stopTime);
if (WindowSize.count()*1000 > N)
startTime = startTime + (WindowSize.count()*1000-N);
ind = (ind + 1) % 10;
std::cout << *count << std::endl;
++(*count);
t->expires_at(t->expires_at() + boost::posix_time::milliseconds(1));
t->async_wait(boost::bind(clockTick,boost::asio::placeholders::error, t, count, currTime));
} // 10ms or 100 times a second
int TimeWindowCounter::getNumOfOrders()
{
int sum = 0;
for (int i = 0; i<= 99; i++)
sum = sum + numberofOrder[i];
return sum;
}
void TimeWindowCounter::run(){
io.run();
}
int main()
{
boost::asio::io_service io;
int count = 0;
TimeAnalyser timeAnalyser;
double currTime = timeAnalyser.getClockTime();
TimeWindowCounter * timewindowCounter = new TimeWindowCounter();
boost::asio::deadline_timer t(io, boost::posix_time::milliseconds(10));
t.async_wait(boost::bind(clockTick,boost::asio::placeholders::error, &t, &count, &currTime));
timewindowCounter->run();
for (int j = 0; j <=100000 ; j++)
timewindowCounter->addOrder();
std::cout << "Final count is " << count << std::endl;
}
HPP:
#ifndef TIMEWINDOWCOUNTER
#define TIMEWINDOWCOUNTER
#include <iostream>
#include <boost/chrono.hpp>
#include <boost/atomic.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <cmath>
#include <unistd.h>
#include "../../Common/TimeAnalyser.hpp"
using namespace std;
class TimeWindowCounter
{
TimeAnalyser timeAnalyser;
boost::asio::io_service io;
public:
TimeWindowCounter();
~TimeWindowCounter();
TimeWindowCounter(double currTime);
boost::atomic<bool> first_order_sent;
boost::chrono::duration<double> interval;
double startTime;
double stopTime;
double endTime;
double currTime;
void init();
int numberofOrders;
int orderCount;
int numberofOrder[99];
int ind;
boost::chrono::duration<double> WindowSize;
int N; // WindowSize
void addOrder();
void clockTick(const boost::system::error_code&, boost::asio::deadline_timer* t, int* count, double* currTime); // 10ms or 100 times a second
int getNumOfOrders();
void timer_thread();
void run();
};
#endif
Compile:
g++ -std=c++11 -o TA TimeWindowCounter.cpp -lboost_chrono -lboost_system
Error:
TimeWindowCounter.cpp: In member function ‘void TimeWindowCounter::clockTick(const boost::system::error_code&, boost::asio::deadline_timer*, int*, double*)’:
TimeWindowCounter.cpp:50:93: error: invalid use of non-static member function
t->async_wait(boost::bind(clockTick,boost::asio::placeholders::error, t, count, currTime));
^
TimeWindowCounter.cpp: In function ‘int main()’:
TimeWindowCounter.cpp:80:26: error: ‘clockTick’ was not declared in this scope
t.async_wait(boost::bind(clockTick,boost::asio::placeholders::error, &t, &count, &currTime));
You're binding an instance member function.
You need to qualify the function name and pass a suitable "this" parameter as the first argument:
t->async_wait(boost::bind(&TimeWindowCounter::clockTick, this, boost::asio::placeholders::error, t, count, currTime));
and
t.async_wait(boost::bind(&TimeWindowCounter::clockTick, timewindowCounter, boost::asio::placeholders::error, &t, &count, &currTime));
respectively.
Live Demo
Live On Coliru
#ifndef TIMEWINDOWCOUNTER
#define TIMEWINDOWCOUNTER
#include <iostream>
#include <boost/chrono.hpp>
#include <boost/atomic.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <cmath>
#include <unistd.h>
//#include "../../Common/TimeAnalyser.hpp"
struct TimeAnalyser {
double getClockTime() const { return 0; }
boost::chrono::duration<double> getDiffTime_rt(double, double) const { return boost::chrono::milliseconds(1); }
};
using namespace std;
class TimeWindowCounter {
TimeAnalyser timeAnalyser;
boost::asio::io_service io;
public:
TimeWindowCounter();
~TimeWindowCounter();
TimeWindowCounter(double currTime);
boost::atomic<bool> first_order_sent;
boost::chrono::duration<double> interval;
double startTime;
double stopTime;
double endTime;
double currTime;
void init();
int numberofOrders;
int orderCount;
int numberofOrder[99];
int ind;
boost::chrono::duration<double> WindowSize;
int N; // WindowSize
void addOrder();
void clockTick(const boost::system::error_code&, boost::asio::deadline_timer* t, int* count,
double* currTime); // 10ms or 100 times a second
int getNumOfOrders();
void timer_thread();
void run();
};
#endif
//#include "TimeWindowCounter.hpp"
#include <iostream>
//#include "../../Common/TimeAnalyser.hpp"
TimeWindowCounter::TimeWindowCounter() { init(); }
void TimeWindowCounter::init() { boost::atomic<bool> first_order_sent(false); }
TimeWindowCounter::TimeWindowCounter(double currTime)
{
first_order_sent = true;
startTime = currTime;
endTime = currTime;
orderCount = 0;
ind = 0;
N = 1000;
for (int j = 0; j <= 99; j++)
numberofOrder[j] = 0;
}
TimeWindowCounter::~TimeWindowCounter() {}
void TimeWindowCounter::addOrder()
{
orderCount++;
numberofOrder[ind] = orderCount;
}
void TimeWindowCounter::clockTick(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t, int* count,
double* currTime)
{
stopTime = *currTime;
WindowSize = timeAnalyser.getDiffTime_rt(startTime, stopTime);
if (WindowSize.count() * 1000 > N)
startTime = startTime + (WindowSize.count() * 1000 - N);
ind = (ind + 1) % 10;
std::cout << *count << std::endl;
++(*count);
t->expires_at(t->expires_at() + boost::posix_time::milliseconds(1));
t->async_wait(boost::bind(&TimeWindowCounter::clockTick, this, boost::asio::placeholders::error, t, count, currTime));
} // 10ms or 100 times a second
int TimeWindowCounter::getNumOfOrders()
{
int sum = 0;
for (int i = 0; i <= 99; i++)
sum = sum + numberofOrder[i];
return sum;
}
void TimeWindowCounter::run() { io.run(); }
int main()
{
boost::asio::io_service io;
int count = 0;
TimeAnalyser timeAnalyser;
double currTime = timeAnalyser.getClockTime();
TimeWindowCounter* timewindowCounter = new TimeWindowCounter();
boost::asio::deadline_timer t(io, boost::posix_time::milliseconds(10));
t.async_wait(boost::bind(&TimeWindowCounter::clockTick, timewindowCounter, boost::asio::placeholders::error, &t, &count, &currTime));
timewindowCounter->run();
for (int j = 0; j <= 100000; j++)
timewindowCounter->addOrder();
std::cout << "Final count is " << count << std::endl;
}
Prints
Final count is 0
Good Morning
I'm implementing a distributed image normalization algorithm an I'm using Boost::mpi with a class Pixel that contain the serialization code,
#ifndef PIXEL_H
#define PIXEL_H
#include <boost/mpi.hpp>
#include <boost/serialization/access.hpp>
class Pixel
{
private:
unsigned char m_red;
unsigned char m_green;
unsigned char m_blue;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar & m_red;
ar & m_green;
ar & m_blue;
}
public:
Pixel();
Pixel(unsigned char red,unsigned char green,unsigned char blue) : m_red(red), m_green(green), m_blue(blue) {};
virtual ~Pixel();
unsigned char getRed();
void setRed(unsigned char val);
unsigned char getGreen();
void setGreen(unsigned char val);
unsigned char getBlue();
void setBlue(unsigned char val);
void setColor (unsigned char red,unsigned char green,unsigned char blue);
};
The main.cpp is
#include <iostream>
#include <boost/mpi.hpp>
#include <vector>
#include "include/Pixel.h"
#include <cstdlib>
#include <ctime>
#define ALTEZZA 2
#define LARGHEZZA 2
namespace mpi=boost::mpi;
int main(int argc, char * argv[]) {
std::cout<<"Inizializzazione dell'ambiente MPI"<<std::endl;
mpi::environment env;
mpi::communicator world;
Pixel **vettore;
int i,j;
//Inizializzazione della matrice di test
if(world.rank() == 0){
std::cout<<"Inizializzazione matrice di test..."<<std::endl;
std::srand(std::time(0));
vettore = new Pixel *[ALTEZZA];
for (i = 0; i < ALTEZZA; i++) {
vettore[i] = new Pixel[LARGHEZZA];
}
for (i = 0; i < ALTEZZA; i++) {
for (j = 0; j < LARGHEZZA; j++) {
vettore[i][j].setColor(std::rand() % 256, std::rand() % 256, std::rand() % 256);
std::cout<<"Vettore["<<i<<"]["<<j<<"] = ("<<int(vettore[i][j].getRed())<<","<<int(vettore[i][j].getGreen())<<","<<int(vettore[i][j].getBlue())<<");"<<std::endl;
}
}
}
if (world.rank() == 0) {
std::cout<<"Invio matrice.."<<std::endl;
world.send(1, 0, vettore[0]);
}else {
Pixel *px;
world.recv(0, 0, px);
for (j = 0; j < LARGHEZZA; j++) {
std::cout<<int(px[j].getRed())<<" "<<int(px[j].getGreen())<<" "<<int(px[j].getBlue())<<std::endl;
}
}
return 0;
}
but when i run the program the cout on the receiving process print wrong value like this
Inizializzazione dell'ambiente MPI
Inizializzazione dell'ambiente MPI
Inizializzazione matrice di test...
Vettore[0][0] = (170,103,165);
Vettore[0][1] = (84,0,186);
Vettore[1][0] = (93,228,162);
Vettore[1][1] = (31,100,204);
Invio matrice..
170 103 165
217 1 0
I think that the problem is the 2d array because if I use std::vector i haven't this problem but I don't understand why.
I would imagine you have several problems (I can't test as I don't have a capable MPI installation..)
Firstly, your send() is wrong, currently you are triggering the overload:
template<typename T> void send(int, int, const T &) const;
But you are trying to send a raw array, I imagine the fix here has to be to pass the count, for example:
world.send(1, 0, vettore[0], 2); // 2 Pixels
Secondly, on the receiver side (this I'm not sure about), but I imagine you need to have a suitable array to read the data into.., for example:
Pixel px[LARGHEZZA];
world.recv(0, 0, px, 2);
I think this should fix your problems...
Hi I'm trying to write an algorithm for solving the producer-consumer problem and I've hit a roadblock. This is the output I am getting from my code:
Producing: 6
6 0 0 0 0 0 0 0 0 0 END
and then the program exits. I'm not sure where I went wrong? Did I do something wrong in creating a circular buffer?
#include <iostream>
#include <pthread.h>
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <fstream>
using namespace std;
#define BUFFER_SIZE 10
void *produce(void *);
void *consume(void *);
int produceItem(void);
void insertItem(int item);
void removeItem(void);
void printBuffer(void);
int head = 0;
int tail = 0;
int item;
int bufferCount = 0;
pthread_t producer, consumer;
pthread_cond_t Buffer_Not_Full=PTHREAD_COND_INITIALIZER;
pthread_cond_t Buffer_Not_Empty=PTHREAD_COND_INITIALIZER;
pthread_mutex_t lock;
sem_t sem_filledSlots;
sem_t sem_emptySlots;
int buffer[BUFFER_SIZE];
int main() {
int emptyCount;
int item;
srand (time(NULL));
sem_init(&sem_filledSlots, 0, 0);
sem_init(&sem_emptySlots, 0, BUFFER_SIZE);
sem_getvalue(&sem_emptySlots, &emptyCount);
pthread_create (&producer, NULL, &produce, NULL);
pthread_create (&consumer, NULL, &consume, NULL);
return 0;
}
void *produce(void *)
{
for(int i = 0; i <15; i++)
{
item = produceItem();
sem_wait(&sem_emptySlots);
pthread_mutex_lock(&lock);
printf("Producing: %d \n", item);
buffer[head] = item;
head = (head + 1) % BUFFER_SIZE;
printBuffer();
pthread_mutex_unlock(&lock);
sem_post(&sem_filledSlots);
}
}
void *consume(void *)
{
for(int i = 0; i <15; i++)
{
sem_wait(&sem_filledSlots);
pthread_mutex_lock(&lock);
printf("Consuming %d \n", buffer[tail]);
buffer[tail] = 0;
tail = (tail + 1) % BUFFER_SIZE;
bufferCount--;
printBuffer();
pthread_mutex_unlock(&lock);
sem_post(&sem_emptySlots);
}
}
int produceItem(void)
{
int x = (rand()%11 + 1);
return x;
}
void printBuffer(void)
{
for(int i = 0; i <BUFFER_SIZE; i++)
{
printf("%d ", buffer[i]);
}
printf("END \n");
}
you're missing pthread_join before exiting the program:
....
pthread_join(producer,NULL);
pthread_join(consumer,NULL);
return 0;
....