I need to create a thread for each incoming person. It works fine creating a thread for each person. But only the last thread lives. the other ones are somehow overwritten by the last one. what am I doing wrong here? Do you see anything wrong with this code?
Person *person;
DWORD bytesRead;
while(1)
{
person = (Person *) malloc( sizeof(Person) );
bytesRead = mailslotRead ( mailbox, &person, sizeof(Person) );
if( bytesRead != 0 )
{
list_append( planets, &person );
threadCreate(personThread, &person );
Sleep(100);
}
}
DWORD WINAPI personThread(Person* person)
{
MessageBox(0, person->name, "New thread created for:", 0);
while(1)
{
person->age += 1;
MessageBox(0, person->name, "person aged", 0);
Sleep(5000);
}
MessageBox(0, person->name, "Thread died", 0);
}