<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def shutdown():
    '''Shut down the SDK.

    :returns: An exception object if an error occurred, a falsy value otherwise.

    :rtype: Exception
    '''
    global _sdk_ref_count #pylint:disable=global-statement
    global _sdk_instance #pylint:disable=global-statement
    global _should_shutdown #pylint:disable=global-statement

    with _sdk_ref_lk:
        logger.debug("shutdown: ref count = %d, should_shutdown = %s", \
                     _sdk_ref_count, _should_shutdown)
        nsdk = nativeagent.try_get_sdk()
        if not nsdk:
            logger.warning('shutdown: SDK not initialized or already shut down')
            _sdk_ref_count = 0
            return None
        if _sdk_ref_count > 1:
            logger.debug('shutdown: reference count is now %d', _sdk_ref_count)
            _sdk_ref_count -= 1
            return None
        logger.info('shutdown: Shutting down SDK.')
        try:
            if _should_shutdown:
                _rc = nsdk.shutdown()
                if _rc == ErrorCode.NOT_INITIALIZED:
                    logger.warning('shutdown: native SDK was not initialized')
                else:
                    nativeagent.checkresult(nsdk, _rc, 'shutdown')
                _should_shutdown = False
        except SDKError as e:
            logger.warning('shutdown failed', exc_info=sys.exc_info())
            return e
        _sdk_ref_count = 0
        _sdk_instance = None
        nativeagent._force_initialize(None) #pylint:disable=protected-access
        logger.debug('shutdown: completed')
        return None