Pickle and Unpickle theano functions

Added a test case to verify if pickle and unpickle a compiled theano function works.
Passed.
I may not follow the code properly here, but it seem that you are grabbing the lock and only releasing it if cache_optimization is set to True.