Patent ID: 8020155

Claim:
A machine implemented method, comprising: causing, by a run time optimizer (RTO) thread executing a RTO at run time, by causing a branch instruction to reference a first version of a function, wherein the RTO comprises redirection code having a same name as a standard library version of the function, wherein the redirection code comprises the branch instruction, wherein the RTO is loaded and linked with the program as a dynamically linked library such that a linkage table of the program references the redirection code based on the redirection code having the same name as the standard library version of the function, wherein the executable code currently has only one program thread of execution that invokes the function, and wherein the first version of the function is a single threaded version that does not ensure multi thread safety; intercepting, by the RTO thread at run time, a request from the program to create another program thread of execution for executing the executable code; detecting, in response to intercepting the request to create another program thread and based on a thread count of a number of program threads, that the executable code transitioned from only the one program thread to having multiple program threads of execution that invokes the function; and in response to detecting that the executable code has multiple threads of execution that invoke the function, rewriting, by the RTO thread, the branch instruction to reference a second version of the function instead of the first version of the function, wherein the second version of the function is a multi threaded version that does ensure multi thread safety.