NewtonWorldCriticalSectionLock

From Newton Wiki
Jump to: navigation, search

NewtonWorldCriticalSectionLock

void NewtonWorldCriticalSectionLock (const NewtonWorld* const newtonWorld, int threadIndex)

Usage

this function block all other threads from executing the same subsequent code simultaneously.

Parameters

  • const NewtonWorld* const newtonWorld
  • int threadIndex

Return

  • (Procedure)

Description

Enters critical section for the given world.

This provides mutual exclusion for the caller thread.

Since Newton became a multithreaded library it is necessary sometimes to lock resources in order to avoid concurrent access to shared resources.

Remarks

  • this function should use to present racing conditions when when a call back ins executed form a mutithreaded loop.
  • In general most call back are thread safe when they do not write to object outside the scope of the call back.
  • this means for example that the application can modify values of object pointed by the arguments and or call that function that are allowed to be call for such callback.
  • There are cases, however, when the application need to collect data for the client logic, example of such case are collecting information to display debug information, of collecting data for feedback.
  • In these situations it is possible the the same critical code could be execute at the same time but several thread causing unpredictable side effect.
  • so it is necessary to block all of the thread from executing any pieces of critical code.
  • Not calling function *NewtonWorldCriticalSectionUnlock* will result on the engine going into an infinite loop.
  • it is important that the critical section wrapped by functions *NewtonWorldCriticalSectionLock* and
  • *NewtonWorldCriticalSectionUnlock* be keep small if the application is using the multi threaded functionality of the engine
  • no doing so will lead to serialization of the parallel treads since only one thread can run the a critical section at a time.

See also

NewtonWorldCriticalSectionUnlock