A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by misho » Sat Jul 26, 2025 9:24 pm
Hello!
I am working with Newton 3.14, and I was wondering - is the library inherently (by default) doing any multithreading?
I have a strict requirement to compile my project into WASM (Web Assembly), and the API I am dealing with offers "large support for the standard C++ library", however, not including multithreading. That is, if I try to include
- Code: Select all
#include <thread>
I get this error:
- Code: Select all
\WASM\wasi-sysroot/include/c++/v1\thread(109,2): error : <thread> is not supported on this single threaded system
So - when I start converting my project into WASM configuration - will I have to worry about this? Or, Newton Dynamics is NOT doing any inherent multithreading?
Thanks!!
-
misho
-
- Posts: 675
- Joined: Tue May 04, 2010 10:13 am
by Julio Jerez » Sun Jul 27, 2025 9:00 pm
You can enable the Thread Emulation define option either in cmake or manually in the header file.
this will run everything on the application’s main thread.
I was working on an Unreal Engine plugin, and unfortunately, UE has a problematic threading system. It tends to crash applications that use multithreading but not with UE threads.
I was never able to fully resolve it, so I ended up using single-threaded emulation instead.
Why aren't you using Newton 4?
Edit:
Switching to Newton 4 offers significant benefits, especially for the kind of simulations you're working on. It's a big improvement when linking objects with large mass differences.
In older versions, the slack in constraints was handled within a non-linear constraint loop using an iterative solver.
Newton 4, however, uses a preconditioned iterative solver that, with a much higher and stable converge rate, that in almost all cases, converges to near zero error.
Only extreme edge cases, like singular matrices caused by double joints or incorrect setups will fail, which is expected and actually the correct behavior in my opinion.
Anyway, that's my recommendation.
-
Julio Jerez
- Moderator

-
- Posts: 12425
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by misho » Tue Jul 29, 2025 11:25 am
Hi Julio, thanks for your explanation!
I have the code working in 3.14, and now I need to show some practical results, and more importantly, I need to see if it works and can be compiled into WASM. If I get it compiling, then I will go back and convert into 4.0 - definitely.
I saw the #include <thread> condition in the code - so, am I to understand that if this is not included (manually, or by current condition), the code reverts to running everything in the application's main thread? If that is the case, that would be the answer to my question.
-
misho
-
- Posts: 675
- Joined: Tue May 04, 2010 10:13 am
by Julio Jerez » Tue Jul 29, 2025 9:52 pm
yes, there is a that include for multi-threading. But it is under the define
DG_USE_THREAD_EMULATION
- Code: Select all
#ifndef DG_USE_THREAD_EMULATION
#include <mutex>
#include <thread>
#include <condition_variable>
#endif
misho wrote:the code reverts to running everything in the application's main thread? If that is the case, that would be the answer to my question.
I do not understand the question, if Mutithreaded is not enabled, the engine run on the thread that created the Newton instance.
if you are using cmake, you can just select Newton_Build_Single_Thread,
or you can just manually set the define in file:
C:\development\newton-dynamics\newton-3.14\sdk\dgCore\dgTypes.h line 156
- Code: Select all
// by default newton run on a separate thread and
// optionally concurrent with the calling thread,
// it also uses a thread job pool for multi core systems.
// define DG_USE_THREAD_EMULATION on the command line for
// platform that do not support hardware multi threading or
// if the and application want to control threading at the application level
//#define DG_USE_THREAD_EMULATION
-
Julio Jerez
- Moderator

-
- Posts: 12425
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 0 guests