1 #ifndef MULTITHREADING_HXX
 2 #define MULTITHREADING_HXX
 3 
 4 #include "Camera.hxx"
 5 #include "Image.hxx"
 6 #include "Scene.hxx"
 7 #include <pthread.h>
 8 
 9 /**
10  * increase performance by using two threads in parallel
11  */
12 class MultiThreading
13 {
14     private:
15         int linenumber;
16 
17     public:
18         pthread_mutex_t mutex;
19         Scene*  scene;
20         Camera* camera;
21         Image*  image;
22 
23     MultiThreading(Scene* scene, Camera* camera, Image* image) : scene(scene), camera(camera), image(image)
24     { 
25         /**
26          * Threads must access the same memory area to exchange data.
27          * To avoid that multiple threads simultaneously edit a variable, use 'mutex'.
28          * Otherwise variables could be in a undefined state.
29         */
30         pthread_mutex_init (&mutex, NULL);
31         linenumber = 0;
32     };
33     
34     /**
35      * get line to render next
36      */
37     int GetNextLine()
38     {   
39         return linenumber++;
40     };
41     
42     virtual ~MultiThreading()
43     {
44         pthread_mutex_destroy(&mutex);
45     }
46     
47 };
48 
49 #endif


syntax highlighted by Code2HTML, v. 0.9.1