You are here:

C++/Use of List with a Singleton Class

Advertisement


Question
Hello,

I am trying to explain a scenario which i tried, I have a singleton class, and when the Instance is created I am creating a List<ListItem Class>. Im the main thread I have a method which is adding Items into the List ( using push_back), and in this method, I am creating a workerthread with a method which will iterate through the list and remove the entries based on a Condition. Do I need to use any kind of locking mechanism?. I am totally new to this C++. Please Help me.

Answer
Yes, you would need to synchronize access to the list. This is the classical producer-consumer scenario.

See:
http://macboypro.com/blog/2009/06/29/producer-consumer-problem-in-c-using-pthrea
http://en.wikipedia.org/wiki/Producer-consumer_problem  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.