Fixed minor bug on shared pointer

The integer used to count thread number was shared between threads
without being synchronized, now they all access separate dynamic
variables.

Signed-off-by: Raffaele Aquilone <aquiloneraf@gmail.com>