threads + class = problem

andres
26 de Mayo del 2004
The problem is not easy , i have a Class Ccliente and a Ciq. You can see the relation between them.Now , from the public method connect() i begin a thread ThreadReceive. This thread is created and works. When i call the

C->packet_handler(buff); the program goes to the correct line and executes iq.find(buff); this call is the one with problems. Inside this function i have lista_ids.begin(); , but it crashes because lista_ids memory address is 0x0. This memory address problem does not happend when i run cliente.iq.find(“something”); from my main program and dont use the thread.



Please read the comments of the source code.

Reply to [email protected]



typedef list <string> id_list;



class Ciq

{

public:

find(string buff);

protected:

id_list lista_ids;

}



Class Ccliente

{

public:

connect();

packet_handler(string buff);

Ciq iq; //made public just for testing

Static UINT ThreadReceive(LPVOID param) //made public just for testing



}



void CCliente::packet_handler(string buff)

{

iq.find(buff);

}



int CCliente::connect()

{

...

AfxBeginThread(ThreadReceive, //nombre de la funcion

(LPVOID)C,

THREAD_PRIORITY_NORMAL,0,0,NULL);

...

}



void Ciq::find(string buff)

{

lista_ids.begin();

///lista_ids memory address here is 0x00 if i call it with the thread

///lista_ids memory address here is OK if i call it from my main program with

///cliente.iq.find(“something”);

}



UINT CCliente::ThreadReceive(LPVOID param)

{

///really short version of the real one.

CCliente* C = (CCliente*) param;

C->packet_handler(buff);

}

Alejandro_
26 de Mayo del 2004
Hola andrés;
quizás pueda ayudarte un artículo muy simple sobre el uso de funciones miembro como funciones thread que puse en:

http://www.char-star.net/thread_f_miembro.htm

Alejandro