I would like to create a separate thread using c++ that does some jobs along with FlexSim simulation and the jobs may fire some events or change states of the model, is it feasible? Is FlexSim thread safe for this use case?
I would like to create a separate thread using c++ that does some jobs along with FlexSim simulation and the jobs may fire some events or change states of the model, is it feasible? Is FlexSim thread safe for this use case?
FlexSim is not thread safe. FlexSim is single threaded and so you have to implement your own thread security.
Here is an example module I made that shows how you can have a thread working and then handing off the data to FlexSim. Also here is an example model I made which is set up to use the module.
This module works by starting a thread by calling startthreadexample(). The thread can do any task (in this case it saves a dummy message every 1 sec) and then posts a windows message which causes the main thread to call the registered node which was registered by threadexampleregisternode(). The registered node then calls getthreadexampledata() and then prints the retrieved data. The thread can be stopped by calling stopthreadexample().
I made this module by cloning and modifying the Flexsim Modules SDK.
Let me know if you have any questions.
Thank you! How can I use this dll in this model? When I run this model, it says startthreadexample command doesn't exist.
You need to install the module by copying its directory into your FlexSim\modules directory.
Please download the Module SDK and read the included documentation to understand how to work with modules.
Also, if FlexSim itself is not thread safe and we have an another thread that adds events to the event queue at the same time as FlexSim, how to prevent conflict in this case?
That's what Jacob's example shows how to do.
You don't add events to the event queue from the other thread. You store data in your dll from the other thread that you need for the event, and you use a callback into the dll from the FlexSim main thread to read that data and generate the events.
You can use std::thread and std::mutex to write that data on a separate thread and read it from FlexSim's main thread without conflicts.
14 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved