thread-safety:
Added more locking to clBuildProgram and mem management
initialization.