Initial threading support, empty function modifications

Basic structure and variables for threading, empty function now affects
itself rather than simply returning an empty clone.
Further threading functionality

Added threading communication code and thread locking. Bug fixes for
threading, callback deferring when threading is executing.