[lockfree] crash in queue

Hi Tim, I tried using lockfree::queue but I keep getting a crash. My configuration: boost 1.53 beta1, g++ 4.5 / clang (from trunk, a few weeks old), both in c+11, i7 6 cores / 12 threads. My test program is pretty much your example, except that my data is not an int but a boost::function. As a note, the crash seems to happen only when I have many consumers. Many producers and one consumer seem to be ok. Am I doing something wrong? Thanks, Christophe #include <boost/thread/thread.hpp> #include <boost/lockfree/queue.hpp> #include <boost/function.hpp> #include <boost/atomic.hpp> boost::lockfree::queue<boost::function<void()> > lfqueue(10000); boost::atomic<bool> done (false); struct empty_task { void operator()()const { } }; void producer(void) { for (int i = 0; i != 10000000; ++i) { boost::function<void()> task = empty_task(); while (!lfqueue.push(task)) { boost::this_thread::yield(); } } } void consumer() { while (!done) { boost::function<void()> res; if (!lfqueue.pop(res)) { boost::this_thread::yield(); } else { res(); } } } void test_lockfree_queue() { boost::thread_group producer_threads, consumer_threads; for (int i = 0; i != 1; ++i) producer_threads.create_thread(producer); for (int i = 0; i != 12; ++i) consumer_threads.create_thread(consumer); producer_threads.join_all(); done = true; consumer_threads.join_all(); } int main() { test_lockfree_queue(); return 0; }

I tried using lockfree::queue but I keep getting a crash. My configuration: boost 1.53 beta1, g++ 4.5 / clang (from trunk, a few weeks old), both in c+11, i7 6 cores / 12 threads.
My test program is pretty much your example, except that my data is not an int but a boost::function. As a note, the crash seems to happen only when I have many consumers. Many producers and one consumer seem to be ok.
Am I doing something wrong?
didn't test your code, but i'm pretty sure that boost::function is violating the requirements of the lockfree queue: * trivial copy constructor * trivial assignment * trivial destructor cheers, tim

On Thu, Jan 24, 2013 at 6:24 PM, Tim Blechmann <tim@klingt.org> wrote:
I tried using lockfree::queue but I keep getting a crash. My configuration: boost 1.53 beta1, g++ 4.5 / clang (from trunk, a few weeks old), both in c+11, i7 6 cores / 12 threads.
My test program is pretty much your example, except that my data is not an int but a boost::function. As a note, the crash seems to happen only when I have many consumers. Many producers and one consumer seem to be ok.
Am I doing something wrong?
didn't test your code, but i'm pretty sure that boost::function is violating the requirements of the lockfree queue: * trivial copy constructor * trivial assignment * trivial destructor
Can these requirements be enforced with static_asserts or concept checks?

didn't test your code, but i'm pretty sure that boost::function is violating the requirements of the lockfree queue: * trivial copy constructor * trivial assignment * trivial destructor Can these requirements be enforced with static_asserts or concept checks?
i haven't merged that commit from trunk to release, as it is not exactly a bug fix, but maybe i should ... tim

My test program is pretty much your example, except that my data is
not an int but a boost::function. As a note, the crash seems to happen only when I have many consumers. Many producers and one consumer seem to be ok.
Am I doing something wrong? didn't test your code
yes ... your code triggers some static assertion failures using current trunk ... iac, i'll backporting that commit ... tim

I tried using lockfree::queue but I keep getting a crash. My configuration: boost 1.53 beta1, g++ 4.5 / clang (from trunk, a few weeks old), both in c+11, i7 6 cores / 12 threads.
My test program is pretty much your example, except that my data is not an int but a boost::function. As a note, the crash seems to happen only when I have many consumers. Many producers and one consumer seem to be ok.
Am I doing something wrong?
didn't test your code, but i'm pretty sure that boost::function is violating the requirements of the lockfree queue: * trivial copy constructor * trivial assignment * trivial destructor
cheers, tim
Hi, oh sorry, I overlooked this. Hmm that's pretty high requirements which leave me little choice other than pointers I guess. Yes, static asserts will help (oh and a bigger font for requirements ;-) ). Thanks, Christophe

didn't test your code, but i'm pretty sure that boost::function is violating the requirements of the lockfree queue: * trivial copy constructor * trivial assignment * trivial destructor
cheers, tim Hi, oh sorry, I overlooked this. Hmm that's pretty high requirements which leave me little choice other than pointers I guess.
there are several reasons for this, e.g. the algorithm copies the payload before knowing if it is valid ... heap-allocating objects inside the data structure and using pointers internally would relax the requirements, but violate the lock-free property ... tim
participants (3)
-
Andrey Semashev
-
Christophe Henry
-
Tim Blechmann