OpenCascade.js
API ReferenceFoundationClassesTKernel

OSD

OCCT package OSD: OSD, OSD_FromWhere, OSD_KindFile, OSD_LoadMode, and 11 more bound classes.

OSD

Set of Operating System Dependent (OSD) tools.

Constructors(1)

Static methods(12)

  • SetSignal(theSignalMode: OSD_SignalMode, theFloatingSignal: boolean): void

    Sets or removes signal and FPE (floating-point exception) handlers. OCCT signal handlers translate signals raised by C subsystem to C++ exceptions inheriting Standard_Failure.
    Windows-specific notes
    Compiled with MS VC++ sets 3 main handlers:

    • Signal handlers (via ::signal() functions) that translate system signals (SIGSEGV, SIGFPE, SIGILL) into C++ exceptions (classes inheriting Standard_Failure). They only be called if function ::raise() is called with one of supported signal type set.
    • Exception handler OSD::WntHandler() (via ::SetUnhandledExceptionFilter()) that will be used when user's code is compiled with /EHs option.
    • Structured exception (SE) translator (via _set_se_translator()) that translates SE exceptions (aka asynchronous exceptions) into the C++ exceptions inheriting Standard_Failure. This translator will be used when user's code is compiled with /EHa option.
      This approach ensures that regardless of the option the user chooses to compile his code with (/EHs or /EHa), signals (or SE exceptions) will be translated into Open CASCADE C++ exceptions.
      MinGW should use SEH exception mode for signal handling to work.
      Linux-specific notes
      OSD::SetSignal() sets handlers (via ::sigaction()) for multiple signals (SIGFPE, SIGSEGV, etc).
      Common notes
      If theFloatingSignal is TRUE then floating point exceptions will generate SIGFPE in accordance with the mask
    • Windows: _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW, see _controlfp() system function.
    • Linux: FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW, see feenableexcept() system function.
      If theFloatingSignal is FALSE then floating point calculations will gracefully complete regardless of occurred exceptions (e.g. division by zero). Otherwise the (thread-specific) FPE flags are set to raise signal if one of floating-point exceptions (division by zero, overflow, or invalid operation) occurs.
      The recommended approach is to call OSD::SetSignal() in the beginning of the execution of the program, in function main() or its equivalent. In multithreaded programs it is advisable to call OSD::SetSignal() or OSD::SetThreadLocalSignal() with the same parameters in other threads where OCCT is used, to ensure consistency of behavior.
      Note that in order to handle signals as C++ exceptions on Linux and under MinGW on Windows it is necessary to compile both OCCT and application with OCC_CONVERT_SIGNALS macro, and use macro OCC_CATCH_SIGNALS within each try{} block that has to catch this kind of exceptions.
      Refer to documentation of Standard_ErrorHandler.hxx for details.
    Parameters (2)
    • theSignalMode
    • theFloatingSignal
  • SetSignal(theFloatingSignal: boolean): void

    Sets signal and FPE handlers. Short-cut for OSD::SetSignal (OSD_SignalMode_Set, theFloatingSignal).

    Parameters (1)
    • theFloatingSignal
  • SetThreadLocalSignal(theSignalMode: OSD_SignalMode, theFloatingSignal: boolean): void

    Initializes thread-local signal handlers. This includes _set_se_translator() on Windows platform, and SetFloatingSignal(). The main purpose of this method is initializing handlers for newly created threads without overriding global handlers (set by application or by OSD::SetSignal()).

    Parameters (2)
    • theSignalMode
    • theFloatingSignal
  • SetFloatingSignal(theFloatingSignal: boolean): void

    Enables / disables generation of C signal on floating point exceptions (FPE). This call does NOT register a handler for signal raised in case of FPE - SetSignal() should be called beforehand for complete setup. Note that FPE setting is thread-local, new threads inherit it from parent.

    Parameters (1)
    • theFloatingSignal
  • Returns signal mode set by the last call to SetSignal(). By default, returns OSD_SignalMode_AsIs.

  • Returns true if floating point exceptions will raise C signal according to current (platform-dependent) settings in this thread.

  • SecSleep(theSeconds: number): void

    Commands the process to sleep for a number of seconds.

    Parameters (1)
    • theSeconds
  • MilliSecSleep(theMilliseconds: number): void

    Commands the process to sleep for a number of milliseconds.

    Parameters (1)
    • theMilliseconds
  • CStringToReal(aString: string, aReal: number): { returnValue: boolean; aReal: number }

    Converts aCstring representing a real with a period as decimal point, no thousand separator and no grouping of digits into aReal.
    The conversion is independent from the current locale.

    Parameters (2)
    • aString
    • aReal
    Returns

    A result object with fields:

    • returnValue: the C++ return value
    • aReal: updated value from the call.
  • ControlBreak(): void

    since Windows NT does not support 'SIGINT' signal like UNIX, then this method checks whether Ctrl-Break keystroke was or not. If yes then raises Exception_CTRL_BREAK.

  • Returns a length of stack trace to be put into exception redirected from signal; 0 by default meaning no stack trace.

    See also
    • Standard_Failure::GetStackString()
  • SetSignalStackTraceLength(theLength: number): void

    Sets a length of stack trace to be put into exception redirected from signal.

    Parameters (1)
    • theLength

OSD_Parallel

Simple tool for code parallelization.
OSD_Parallel class provides simple interface for parallel processing of tasks that can be formulated in terms of "for" or "foreach" loops.
To use this tool it is necessary to:

  • organize the data to be processed in a collection accessible by iteration (usually array or vector);
  • implement a functor class providing operator () accepting iterator (or index in array) that does the job;
  • call either For() or ForEach() providing begin and end iterators and a functor object.
    Iterators should satisfy requirements of STL forward iterator. Functor
classFunctor { public: voidoperator()([processinginstance])const { //... } };

The operator () should be implemented in a thread-safe way so that the same functor object can process different data items in parallel threads.
Iteration by index (For) is expected to be more efficient than using iterators (ForEach).
Implementation uses TBB if OCCT is built with support of TBB; otherwise it uses ad-hoc parallelization tool. In general, if TBB is available, it is more efficient to use it directly instead of using OSD_Parallel.

Constructors(1)

Static methods(3)

OSD_Thread

A simple platform-intependent interface to execute and control threads.

Constructors(2)

  • Empty constructor.

  • Initialize the tool by the thread function.
    Note: On Windows, you might have to take an address of the thread function explicitly to pass it to this constructor without compiler error

    Parameters (1)
    • other

Static methods(1)

  • Current(): number

    Auxiliary: returns ID of the current thread.

Instance methods(4)

  • Assign(other: OSD_Thread): void

    Copy thread handle from other OSD_Thread object.

    Parameters (1)
    • other
  • SetPriority(thePriority: number): void
    Parameters (1)
    • thePriority
  • Detach(): void

    Detaches the execution thread from this Thread object, so that it cannot be waited. Note that mechanics of this operation is different on UNIX/Linux (the thread is put to detached state) and Windows (the handle is closed). However, the purpose is the same: to instruct the system to release all thread data upon its completion.

  • GetId(): number

    Returns ID of the currently controlled thread ID, or 0 if no thread is run.

OSD_ThreadPool

Class defining a thread pool for executing algorithms in multi-threaded mode. Thread pool allocates requested amount of threads and keep them alive (in sleep mode when unused) during thread pool lifetime. The same pool can be used by multiple consumers, including nested multi-threading algorithms and concurrent threads:

  • Thread pool can be used either by multi-threaded algorithm by creating OSD_ThreadPool::Launcher. The functor performing a job takes two parameters - Thread Index and Data Index: void operator(int theThreadIndex, int theDataIndex){} Multi-threaded algorithm may rely on Thread Index for allocating thread-local variables in array form, since the Thread Index is guaranteed to be within range OSD_ThreadPool::Lower() and OSD_ThreadPool::Upper().
  • Default thread pool (OSD_ThreadPool::DefaultPool()) can be used in general case, but application may prefer creating a dedicated pool for better control.
  • Default thread pool allocates the amount of threads considering concurrency level of the system (amount of logical processors). This can be overridden during OSD_ThreadPool construction or by calling OSD_ThreadPool::Init() (the pool should not be used!).
  • OSD_ThreadPool::Launcher reserves specific amount of threads from the pool for executing multi-threaded Job. Normally, single Launcher instance will occupy all threads available in thread pool, so that nested multi-threaded algorithms (within the same thread) and concurrent threads trying to use the same thread pool will run sequentially.
    This behavior is affected by OSD_ThreadPool::NbDefaultThreadsToLaunch() parameter and Launcher constructor, so that single Launcher instance will occupy not all threads in the pool allowing other threads to be used concurrently.
  • OSD_ThreadPool::Launcher locks thread one-by-one from thread pool in a thread-safe way.
  • Each working thread catches exceptions occurred during job execution, and Launcher will throw Standard_Failure in a caller thread on completed execution.

Constructors(1)

  • constructor(theNbThreads?: number): OSD_ThreadPool

    Main constructor. Application may consider specifying more threads than actually available (OSD_Parallel::NbLogicalProcessors()) and set up NbDefaultThreadsToLaunch() to a smaller value so that concurrent threads will be able using single Thread Pool instance more efficiently.

    Parameters (1)
    • theNbThreads
      threads number to be created by pool (if -1 is specified then OSD_Parallel::NbLogicalProcessors() will be used)

Static methods(3)

Instance methods(9)

  • HasThreads(): boolean

    Return TRUE if at least 2 threads are available (including self-thread).

  • Return the lower thread index.

  • Return the upper thread index (last index is reserved for self-thread).

  • NbThreads(): number

    Return the number of threads; >= 1.

  • Return maximum number of threads to be locked by a single Launcher object by default; the entire thread pool size is returned by default.

  • SetNbDefaultThreadsToLaunch(theNbThreads: number): void

    Set maximum number of threads to be locked by a single Launcher object by default. Should be set BEFORE first usage.

    Parameters (1)
    • theNbThreads
  • IsInUse(): boolean

    Checks if thread pools has active consumers.

  • Init(theNbThreads: number): void

    Reinitialize the thread pool with a different number of threads. Should be called only with no active jobs, or exception Standard_ProgramError will be thrown!

    Parameters (1)
    • theNbThreads

OSD_WhoAmI

Properties(15)