cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.53k stars 1.66k forks source link

Checking size_approx() == 0 segfault in this case #306

Closed jchen706 closed 2 years ago

jchen706 commented 2 years ago

Sefgault Error with gdb output as

Program received signal SIGSEGV, Segmentation fault.
0x000055555555491a in std::__uniq_ptr_impl<moodycamel::LightweightSemaphore, void (*)(moodycamel::LightweightSemaphore*)>::_M_ptr() const ()
(gdb) 
#include <atomic> 
#include "blockingconcurrentqueue.h"
#include "pthread.h"
#include <iostream>

struct kronos {
  void** x; 
} kronos;

// using kernel_queue = moodycamel::BlockingConcurrentQueue<kronos *>;

struct scheduler {
    moodycamel::BlockingConcurrentQueue<struct kronos *>* kernelQueue;
};

static scheduler* s;

int main ()
{
  s = new scheduler;

  if(s->kernelQueue->size_approx() == 0) {
    printf("Equal to 0 \n");
  }
}
cameron314 commented 2 years ago

You haven't allocated a queue, just an uninitialized pointer to one.

jchen706 commented 2 years ago

Thanks!