Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 16:37:24 +0000



Post From: C++ threads inside a ACSIL study?

[2023-02-08 20:34:57]
User133994 - Posts: 80
Ok, now I need some expert help...I think it has to do with pointers

A) <snippet only, huge source base> this non-pointer io_service object version compiles and works as expected:

s11n_example::client* pClient = reinterpret_cast<s11n_example::client*>(sc.GetPersistentPointer(pClientKeys[0]));

boost::asio::io_service io_service;
sc.SetPersistentPointer(pClientKeys[0], new s11n_example::client(io_service, "127.0.0.1", std::to_string(12344), sc));
io_service.run();


B) this pointer to io_service object version compiles but "doesn't" work (even the graph name is not shown in the "add Custom Study" dialogue, just the scsf_Client function name shows...weird)

boost::asio::io_service* p_io_service = reinterpret_cast<boost::asio::io_service*>(sc.GetPersistentPointer(ioServiceKey));

if(p_io_service == nullptr){
  //all threads need the io_service
  sc.SetPersistentPointer(ioServiceKey, new boost::asio::io_service);
}
sc.SetPersistentPointer(pClientKeys[0], new s11n_example::client(*p_io_service, "127.0.0.1", std::to_string(12344), sc));
p_io_service->run();

Of course, I can get the pointers version with threads to work in a main.c file--easy. The problem is integrating it into a custom study scsf_ function--where the main doesn't exist and pointer logic has to be persistent...

Any assistance appreciated.

Thanks!