I have two threads:
-
Main thread :
- Main thread is listening for HTTP requests,
- Main thread registers handler to HTTP request used for long polling
-
Second thread:
- Getting data from different socket.
- if it finds something in data from socket, updates thread local storage, and IF Main thread has HTTP request pending it sends data to it somehow.
How do I make Main thread and second thread communicate to each other?
Main Thread http handler pseudocode:
function mg_handler(request){
var handle = parseHandle(request.data);
var storage_name = parseStorageName(request.data);
var response = WaitForResponse(handle,storage_name);
mg_printf(rasponse);
return;
}
Second thread pseudocode:
var storage
function t_run()
{
var buf
while(1){
recvfrom(socket,buf);
var result;
bool found_something = search(buf,result);
if(found_something){
update(storage,result);
//if WaitForResponse is waiting let it continue by sending storage to it somehow.
//???
}
}
cleanup:
return;
}
Aucun commentaire:
Enregistrer un commentaire