Search Results

Search found 2 results on 1 pages for 'toeplitz'.

Page 1/1 | 1 

  • std::thread and class constructor and destructor

    - by toeplitz
    When testing threads in C++11 I have created the following example: #include <iostream> #include <thread> class Foo { public: Foo(void) { std::cout << "Constructor called: " << this << std::endl; } ~Foo(void) { std::cout << "Destructor called: " << this << std::endl; } void operator()() const { std::cout << "Operatior called: " << this << std::endl; } }; void test_normal(void) { std::cout << "====> Standard example:" << std::endl; Foo f; } void test_thread(void) { std::cout << "====> Thread example:" << std::endl; Foo f; std::thread t(f); t.detach(); } int main(int argc, char **argv) { test_normal(); test_thread(); for(;;); } Which prints the following: Why is the destructor called 6 times for the thread? And why does the thread report different memory locations?

    Read the article

  • OpenGL multiple threads, variable handling [closed]

    - by toeplitz
    I have written an OpenGL program which runs in the following way: Main: - Initialize SDL - Create thread which has the OpenGL context: - Renderloop - Set camera (view) matrix with glUniform. - glDrawElements() .... etc. - Swapbuffers(); - Main SDL loop handling input events and such. - Update camera matrix of type glm::mat4. This is how I pass my camera object to the class that handles opengl. Camera *cam = new Camera(); gl.setCam(cam); where void setCam(Camera *camera) { this->camera = camera; } For rendering in the opengl context thread, this happens: glm::mat4 modelView = camera->view * model; glUniformMatrix4fv(shader->bindUniform("modelView"), 1, GL_FALSE, glm::value_ptr(modelView)); In the main program where my SDL and other things are handles I then recompute the view matrix. This his working fine without me using any mutex locks. Is this correct? On the other hand, I add objects to my scene by an "upload queue" and in this case I have to mutex lock my upload queue vector (vector class type) when adding items to it or else the program crashes. In summary: I recompute my matrix in a different thread and then use it in the opengl thread without any mutex lock. Why is this working? Edit: I think my question is similar to what was asked here: Should I lock a variable in one thread if I only need it's value in other threads, and why does it work if I don't?, only in my case it is even more simple with only one matrix being changed.

    Read the article

1