I am trying to use ConcurrentQueue to log items into a file on a separate thread:
https://github.com/KjellKod/Moody-Camel-s-concurrentqueue
This works:
// declared on the top of the file
moodycamel::ConcurrentQueue<MyType> q; // logger queue
. . .
int MyCallbacks::Event(MyType* p)
{
MyType item = (MyType)*p;
q.enqueue(item);
. . .
// pthread
void* Logger(void* arg) {
MyType.item;
while (true)
if (!q.try_dequeue(item))
This doesnt (object appears to be corrupted after dequeue:
// declared on the top of the file
moodycamel::ConcurrentQueue<MyType*> q; // logger queue
. . .
int MyCallbacks::Event(MyType* p)
{
MyType item = (MyType)*p;
q.enqueue(&item);
. . .
// pthread
void* Logger(void* arg) {
MyType* item;
while (true)
if (!q.try_dequeue(item))
also tried this in the Event
- still doesnt work (the &newdata always prints same address):
auto newdata = std::move(data);
printf(" - pointers - new: %p old: %p\n", &newdata, &data);
q.enqueue(&newdata);
Am I doing it wrong or is it the queue doesnt support pointers?