Funcionou aqui
void* Produce(void* param)
{
Item* itemP = (Item*) param;
sem_wait(empty);
sem_wait(lock);
Item item;
snprintf(item.msg, 100, "%lu_msg_%i", pthread_self(),
item.msgIndex);
shared.buffer[shared.firstEmpty] = item;
shared.firstEmpty = (shared.firstEmpty+1)%BUFFER_SIZE;
printf("Producer %i produced %s on buffer %i\n", itemP-
>threadIndex, item.msg, shared.firstEmpty);
memcpy(sharedMem, &shared, sizeof(Shared) + BUFFER_SIZE);
sem_post(lock);
sem_post(full);
sleep(.5);
return NULL;
}
Mas, de repente, quebrou! Estou recebendo este erro no linuxlite:
virtual-machine:~/Desktop/projects/project1_new$ gcc -o producer
producer.c -pthread -lrt
virtual-machine:~/Desktop/projects/project1_new$ ./producer
Arguments given:
argv[0] = ./producer
Producer 1 produced 140377718953728_msg_0 on buffer 1
./producer: symbol lookup error: ./producer: undefined symbol:
sem_post, version GLIBC_2.2.5