1. A computer program product comprising a computer usable medium tangibly embodying computer readable program code for defining code to provide a locking mechanism for self-modifying code in a multi-thread environment, the self-modifying code comprising helper code callable to modify instructions in a defined block of the self-modifying code, said computer program product comprising: computer readable program code means for defining an atomic compare and exchange instruction in the locking mechanism, the defined atomic compare and exchange instruction for carrying out a comparison of an unreserved lock value with a first instruction in the defined block of self-modifying code, the defined atomic compare and exchange instruction for exchanging the first instruction in the defined block of self-modifying code with a self-loop instruction where the comparison indicates that the unreserved lock value matches the first instruction in the defined block of self-modifying code; computer readable program code means for defining code to return execution to the first instruction in the defined block of self-modifying code where the comparison indicates that the unreserved lock value does not match the first instruction in the defined block of self-modifying code; and computer readable program code means for defining code to permit the remainder of the helper code to be executed to carry out modifications in the defined block of self-modifying code, including as a last step an atomic store to replace the self-loop instruction with a modified instruction, where the comparison indicates that the unreserved lock value matches the first instruction in the defined block of self-modifying code.