I created my own linux apache module in C but after installing it on the server, I found out that in a day, the server receives at least 1,000 requests of which 4 return a segmentation fault message in the error log. I believe this will get worse as the requests increase and I believe its because my module may be encountering what is known as a race condition.
I've read that race conditions can even happen in very few lines of code as follows:
int x=5;
if (x < 6) x++;
In a multi-threaded situation, I think x could exceed 6.
Theres similar documentation that has short code demonstrating a race condition at this URL:
http://ift.tt/1vW6yCI
What I want to know is the best way to handle a race condition. If I go with mutex based functions, then the code may work well but then there may be large delays because the time spent in the critical section defined by mutex would be the time the rest of the server will be held up.
Another option is thread-local storage which I'm interested in but I'm not sure exactly how to implement that whilst avoiding mutex.
My only other option I feel I have which would otherwise be drastic is to have only ONE apache process running on the entire server.
I'm open to other ideas for handling race conditions but I want something that would work very fast. I want to avoid segfaults. I expect my code to be executed at least 1000 times a second, if not more.
Any suggestions? Maybe there's a new race management technology I'm not aware of?
Aucun commentaire:
Enregistrer un commentaire