Re: [Cppcms-users] singleton per thread
Brought to you by:
artyom-beilis
|
From: Daniel V. <chi...@gm...> - 2010-09-28 21:53:53
|
Hello.
The following simple code cause segmentation fault with both
booster::thread_specific_ptr and boost::thread_specific_ptr versions
when a client call "sum" rpc method.
I don't know why.
I missing something?
Thank you.
#include <cppcms/application.h>
#include <cppcms/service.h>
#include <cppcms/applications_pool.h>
#include <cppcms/rpc_json.h>
#include <booster/thread.h>
booster::thread_specific_ptr<int> thread_int;
class json_service : public cppcms::rpc::json_rpc_server {
public:
json_service(cppcms::service &srv) :
cppcms::rpc::json_rpc_server(srv)
{
bind("sum",cppcms::rpc::json_method(&json_service::sum,this),method_role);
thread_int.reset(new int(0));
}
void sum(int x,int y)
{
// FIXME: this line cause segmentation fault
std::cout << "thread_int = " << (*thread_int) << std::endl;
return_result(x+y);
}
};
int main(int argc, char **argv)
{
try {
cppcms::service srv(argc,argv);
srv.applications_pool().mount( cppcms::applications_factory<json_service>());
srv.run();
}
catch(std::exception const &e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
On Tue, 2010-09-28 at 14:05 -0700, Artyom wrote:
> Store it as member of your applications,
> application instances are cached.
>
> You can also use booster::thread_specific_ptr
>
> See as example wikipp.
> Artyom
>
> P.S.: Soci has connection pool as well.
>
>
> ----- Original Message ----
> > From: Daniel Vallejos <chi...@gm...>
> > To: cpp...@li...
> > Sent: Tue, September 28, 2010 7:44:14 PM
> > Subject: [Cppcms-users] singleton per thread
> >
> > Hello.
> >
> > I use soci for database access.
> >
> > The soci session object is not "thread safe".
> >
> > AFAIK each cppcms::application object runs in a thread.
> >
> > Then I need a "singleton per thread" or "thread local storage".
> >
> > How to accomplish this with cppcms?
> >
> > I try to use "boost::thread_specific_ptr" with no luck (segmentation
> > fault).
> >
> >
> > Thanks.
> >
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Start uncovering the many advantages of virtual appliances
> > and start using them to simplify application deployment and
> > accelerate your shift to cloud computing.
> > http://p.sf.net/sfu/novell-sfdev2dev
> > _______________________________________________
> > Cppcms-users mailing list
> > Cpp...@li...
> > https://lists.sourceforge.net/lists/listinfo/cppcms-users
> >
>
>
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
|