Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Multi-Threading with VL
Can I use VL in multi-thraded applications?

Yes! Just like you can use OpenGL in multi-threaded applications. But, you have to know what you are doing. VL was designed to make it possible to be used in multi-threaded applications, but not to make multi-threaded applications development dumb-proof! So you will have to follow certain guide lines and use a few precautions common to all multi-threaded applications.

Also VL does not provide an OS-independent threading library, just a few abstract classes, such as vl::IMutex and vl::ScopedMutex, required to interoperate with your favourite threading api.

Does VL use multi-threading?

VL does not provide any out of the box multi-threading tricks or optimizations as those are out of the scope and purpose of VL. VL is a generic framework to be used to create your own rendering pipeline. Therefore making your rendering pipeline multi-threaded is up to you because it's heavily dependent on the architecture that you choose.

It is important also not to confuse multi-threaded application with multi-threaded rendering. Keep in mind that, unless your rendering is CPU bound, i.e. your GPU is starving, performing multiple renderings at the same time, is probably going to impact negatively the efficiency of the GPU! Always try to optimize to the limit your single-thread rendering pipeline and work on your application's specific CPU bottlenecks before considering issuing OpenGL commands from multiple threads.

Is VL thread-safe?

We have to distinguish between thread-safety and reentrancy. See http://doc.qt.nokia.com/latest/threads-reentrancy.html for a nice introduction to the concept. Strictly speaking, VL is not thread-safe. That actually would be very bad performance-wise. As you probably expect, you can't call the same method of the same objects with the same parameters from two different threads and expect VL to produce predictable results unless you provide some kind of synchronization! However VL is designed to be reentrant (see below for the details) which in this case is the important bit of information in order to develop performant multi-threaded applications.

Guidelines to develop multi-threaded applications using VL

In a nutshell you can safely use VL in multi-threaded applications by following the four following rules:

Remarks