Improve some performances

Avoid string copies by using current location in the original string,
instead of taking the tail at each step.
Use specific thread queue

The thread queue maintains a set of program cointers. If a thread
already exists for a given program pointer, it is not necessary to add
it to the queue.