Skip to content

ocl: Change static variable order in cl_context.cpp to avoid crashes dur...#3337

Merged
opencv-pushbot merged 1 commit intoopencv:2.4from
tstellarAMD:2.4-ocl-context-cleanup-fix
Oct 16, 2014
Merged

ocl: Change static variable order in cl_context.cpp to avoid crashes dur...#3337
opencv-pushbot merged 1 commit intoopencv:2.4from
tstellarAMD:2.4-ocl-context-cleanup-fix

Conversation

@tstellarAMD
Copy link
Copy Markdown
Contributor

...ing destruction

ContextImpl::currentContext contains a reference to one of the
DeviceInfoImpl objects from:

static std::vector global_devices;

ContextImpl::currentContext is destroyed in the destructor
for the statically defined object __module, and relies on its
DeviceInfoImpl reference to query some hardware features while
being destroyed.

This means that we need to ensure that the global_devices vector is
destroyed affter __module, otherwise ContextImpl::currentContext's
DeviceInfoImpl reference will no longer be valid when __module is
destroyed.

Since these variables are all confined to a single compilation unit,
they will be destructed from bottom to top, so we need to make sure
that __module is the bottom definition so it can be destroyed first.

…during destruction

ContextImpl::currentContext contains a reference to one of the
DeviceInfoImpl objects from:

static std::vector<DeviceInfoImpl> global_devices;

ContextImpl::currentContext is destroyed in the destructor
for the statically defined object __module, and relies on its
DeviceInfoImpl reference to query some hardware features while
being destroyed.

This means that we need to ensure that the global_devices vector is
destroyed affter __module, otherwise ContextImpl::currentContext's
DeviceInfoImpl reference will no longer be valid when __module is
destroyed.

Since these variables are all confined to a single compilation unit,
they will be destruct from bottom to top, so we need to make sure
that __module is the bottom definition so it can be destroyed first.
@alalek
Copy link
Copy Markdown
Member

alalek commented Oct 15, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants