pointer problem with multiple thread

Hi,

I have a problem with a pointer, but as i'm not a native english speaker, here is my problem (this not my code, it is just to explain) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Main {
	TaskQueue* task_queue;
	Network*   net;
	Handler*   handler;
	
	Main() {
		 task_queue = new TaskQueue();
		 handler = new Handler(task_queue);
		 net = new Network(handler);
		 net.launch();
	}
}

class Handler {
	TaskQueue* task_queue;

	Handler(TaskQueue* p_queue) {
		task_queue = p_queue;
	}
	
	void handle(buffer) {
		if(task_queue) // <- crash
			task_queue->addTask(new Task(buffer));
	}
	
}

class Network {
	Handler* handler;
	
	Network(Handler* p_handler) {
		handler = p_handler;
	}
	
	static void run(void* data) {  // different thread
		char buffer[1024];
		Network* this_ptr = (Network*)data;
		
		while(true) {
			this_ptr->socket->read(buffer);
			this_ptr->handler->handle(buffer);
		}
	}
	
	void launch() {
		Thread thread(run, this); // thread sfml
		thread.launch();
	}
}


I'm programming with visual c++ 2010.

Thanks for reading
Last edited on
Topic archived. No new replies allowed.