Boost logo

Boost Users :

From: Ken Klose (ken.klose_at_[hidden])
Date: 2007-04-28 17:19:53


Thanks for replying!

The operator()() method is just a stub at the moment:

void PublishedListener::operator()()
{ this->run(); }

void PublishedListener::run()
{ cout << "Hooray! My thread is running" << endl; }

I tried stepping through the construction of the thread and it looks
like the problem is occurring somewhere in the construction of the
function0<void>. As a test I changed the constructor to this:

PublishedListener::PublishedListener(string directory)
{
        cout << "1" << endl;
        function0<void> runnable(*this);
        cout << "2" << endl;
        _thread = new thread(runnable);
        cout << "3" << endl;
}

And I get the problem between 1 and 2.

Thanks,
Ken

PS - I see Peter Dimov suggested I use ref. I'm going to try that now
and reply to his post.

"Digvijoy Chatterjee" <digvijoy.c_at_[hidden]> wrote in message
news:<2f7228250704271831y58640424ld32d3cfe0c1bbc50_at_[hidden]>...
> On 4/27/07, Ken Klose <ken.klose_at_[hidden]> wrote:
> >
> > I've got a singleton object that is trying to run its operator()
method in
> > a
> > separate thread, but I'm getting a segfault when I construct the
thread
> > object:
> >
> > PublishedListener::PublishedListener(string directory)
> > {
> > _thread = new thread(*this); // segfault here
> > }
> >
> > PublishedListener.h:
> > class PublishedListener
> > {
> > public:
> > static PublishedListener &getInstance();
> > void run();
> > void operator()();
> > boost::filesystem::path getItemDirectory();
> > virtual ~PublishedListener();
> > private:
> > PublishedListener(std::string directory);
> > static PublishedListener *_instance;
> > boost::thread *_thread;
> > boost::filesystem::path *itemDirectory;
> > };
> >
> > Thanks in advance!
> >
> Are you sure the implementation of operator()() isnt seg faulting, the
> thread should be able to invoke it properly and i dont see any reason
for
> the thread instantiation to segfault..
> HTH
> Digz
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net