Hi CornedBee and vart, thank's for your time and explanations.
So I should understand that the o.s. will give to each function execution a part of memory to do it's work?
I'm doing the next
Code:
...
//when the server accepts a connection, sends de socket as the parameter to the new thread
s=accept(s,(sockaddr*)&client_descriptor,&client_descriptor_size);
HANDLE tasca=CreateThread(0,0,ProcServei,(void*)s,0,&idTasca);
if(tasca==NULL) {printf("Error creant tasca per la connexio entrant.\n");}
CloseHandle(tasca);
...
DWORD WINAPI ProcServei(void* sidx)
{
SOCKET sc=(SOCKET)sidx;
workWithTheClient(sc);
endTheConectionAndTheSocket(*s);
return 0;
}
void workWithTheClient(SOCKET s)
{
REQUEST r;
getClientRequest(&r);
evalClientRequest(&r);
freeRequest(&r);
}
bool getClientRequest(LPREQUEST r)
{
//receives the client request
r.file=(char*)malloc(client_filerequest_size);
if(!r.file) {return false;}
//writes the file request to the struct value for it
return true;
}
bool evalClientRequest(LPREQUEST r)
{
//validate the request, if is available, etc...
//if necessary modifyes the request struct
return true;
}
//the REQUEST struct is defined in an included file at the begin of the code
typedef struct _REQUEST
{
char *file;
} REQUEST,*LPREQUEST;
It's only a plan explanation, but my program functions are similar (and longer). My doublt is: the 'procServei()' function can be called several times (not at the same time, it depends on the incoming connections), but once that thread have been started, is possible that more that 1 thread calls at the same time the 'evalClientRequest()' function; I'm afraid that in certain moment (or with certain conditions), the data of the function called by thread #1 can be mixed with the data called by the thread #2 at the same time (or if not called at the same time, executed in coincident moment).
Because I never have used threads (exept for practise), I'm not sure of how to handle that all.
Thank's
Niara