<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://www.khronos.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.2.4"
          urlbase="http://www.khronos.org/bugzilla/"
          
          maintainer="webmaster@khronos.org"
>

    <bug>
          <bug_id>296</bug_id>
          
          <creation_ts>2010-04-26 08:41:00 -0700</creation_ts>
          <short_desc>cl.hpp: reference counting bug</short_desc>
          <delta_ts>2011-08-30 09:17:08 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>OpenCL</product>
          <component>Header Files</component>
          <version>1.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Markus Grabner">markus.grabner</reporter>
          <assigned_to name="Neil Trevett">ntrevett</assigned_to>
          <cc>bgaster</cc>
    
    <cc>sschuberth</cc>
          <qa_contact name="OpenCL Working Group">opencl</qa_contact>

      

      

      

          <long_desc isprivate="0">
            <commentid>918</commentid>
            <who name="Markus Grabner">markus.grabner</who>
            <bug_when>2010-04-26 08:41:16 -0700</bug_when>
            <thetext>&lt;Please comment on your experience with the C++ bindings to OpenCL 1.0 here,
including any bugs you encounter as well as suggestions for improvement. If
you are having problems, please try to provide a complete example including
source code demonstrating the problem as well as describing the OS, C++
compiler, and compiler options used.&gt;</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>919</commentid>
            <who name="Markus Grabner">markus.grabner</who>
            <bug_when>2010-04-26 08:51:28 -0700</bug_when>
            <thetext>(In reply to comment #0)
&gt; &lt;Please comment on your experience with the C++ bindings to OpenCL 1.0 here,
&gt; including any bugs you encounter as well as suggestions for improvement. If
&gt; you are having problems, please try to provide a complete example including
&gt; source code demonstrating the problem as well as describing the OS, C++
&gt; compiler, and compiler options used.&gt;

Sorry, didn&apos;t expect that clicking the back button discards the text, so here it is:

cl::CommandQueue::getInfo&lt;CL_QUEUE_CONTEXT&gt;() doesn&apos;t increase the reference count of the cl::Context object returned by this method. This results in a program crash when the destructur is called for the unreferenced instance. The problem probably exists for other getInfo&lt;...&gt; variants since the code is shared.

This file demonstrates the problem. The program crashes in ReferenceHandler&lt;cl_context&gt;::release(), which is invoked from cl::Context::~Context(). If the context&apos;s reference count is increased explicitly (by setting &quot;#if 1&quot; in line 47), the program finishes without error.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>920</commentid>
              <attachid>40</attachid>
            <who name="Markus Grabner">markus.grabner</who>
            <bug_when>2010-04-26 08:52:30 -0700</bug_when>
            <thetext>Created attachment 40
demonstrate reference counting bug</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>921</commentid>
            <who name="Benedict Gaster">bgaster</who>
            <bug_when>2010-04-26 10:40:45 -0700</bug_when>
            <thetext>This is a known problem and something we are working on, unlike many of the other bugs it does not have a straightforward solution.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>922</commentid>
            <who name="Markus Grabner">markus.grabner</who>
            <bug_when>2010-04-27 03:26:53 -0700</bug_when>
            <thetext>I see. Is there a public discussion on this issue elsewhere? I would like to contribute since the workaround I&apos;m currently using is quite ugly :-)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>923</commentid>
            <who name="Benedict Gaster">bgaster</who>
            <bug_when>2010-04-27 10:41:10 -0700</bug_when>
            <thetext>There is general discussion of the C++ bindings on the OpenCL forum here:

http://www.khronos.org/message_boards/viewtopic.php?f=28&amp;t=1415</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>927</commentid>
              <attachid>41</attachid>
            <who name="Markus Grabner">markus.grabner</who>
            <bug_when>2010-05-03 11:38:03 -0700</bug_when>
            <thetext>Created attachment 41
proposed patch for reference counting bug

This is a proposed patch for this issue:
*) define a template function &quot;fixReferenceCount()&quot; which does nothing
*) overload this function for all relevant types (e.g., cl::Context), and call their retain() method
*) call &quot;fixReferenceCount()&quot; for data returned by the native OpenCL functions (in GetInfoHelper::get())</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>1188</commentid>
            <who name="Sebastian Schuberth">sschuberth</who>
            <bug_when>2011-01-07 07:08:21 -0800</bug_when>
            <thetext>This post says reference counting was fixed:

http://www.khronos.org/message_boards/viewtopic.php?p=7692#p7692

Can the OP confirm?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>1461</commentid>
            <who name="Benedict Gaster">bgaster</who>
            <bug_when>2011-08-30 09:17:08 -0700</bug_when>
            <thetext>Reference counting is fixed and so closing.</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>40</attachid>
            <date>2010-04-26 08:52:00 -0700</date>
            <delta_ts>2010-04-26 08:52:30 -0700</delta_ts>
            <desc>demonstrate reference counting bug</desc>
            <filename>opencl_bug.cpp</filename>
            <type>text/plain</type>
            <size>1750</size>
            <attacher>markus.grabner</attacher>
            
              <data encoding="base64">LyoNCg0KCSBjbDo6Q29tbWFuZFF1ZXVlOjpnZXRJbmZvPENMX1FVRVVFX0NPTlRFWFQ+KCkgZG9l
c24ndCBpbmNyZWFzZSB0aGUNCgkgcmVmZXJlbmNlIGNvdW50IG9mIHRoZSBjbDo6Q29udGV4dCBv
YmplY3QgcmV0dXJuZWQgYnkgdGhpcyBtZXRob2QuIFRoaXMNCgkgcmVzdWx0cyBpbiBhIHByb2dy
YW0gY3Jhc2ggd2hlbiB0aGUgZGVzdHJ1Y3R1ciBpcyBjYWxsZWQgZm9yIHRoZQ0KCSB1bnJlZmVy
ZW5jZWQgaW5zdGFuY2UuIFRoZSBwcm9ibGVtIHByb2JhYmx5IGV4aXN0cyBmb3Igb3RoZXIg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5kIHF1ZXVlOg0KCQljbDo6Q29tbWFuZFF1ZXVl
IHF1ZXVlKGNvbnRleHQsIGRldmljZXNbMF0sIDApOw0KDQoJCS8vIHByaW50IGN1cnJlbnQgY29u
dGV4dCByZWZlcmVuY2UgY291bnQ6DQoJCWNvdXQgPDwgInJlZiBjb3VudCA9ICIgPDwgY29udGV4
dC5nZXRJbmZvPENMX0NPTlRFWFRfUkVGRVJFTkNFX0NPVU5UPigpIDw8IGVuZGw7DQoNCgkJLy8g
YWNjZXNzIGNvbnRleHQgYXNzb2NpYXRlZCB3aXRoIGNvbW1hbmQgcXVldWU6DQoJCWNsOjpDb250
ZXh0IGNvbnRleHQyKHF1ZXVlLmdldEluZm88Q0xfUVVFVUVfQ09OVEVYVD4oKSk7DQoNCiNpZiAw
DQoJCS8vIElmIHRoZSBjb250ZXh0J3MgcmVmZXJlbmNlIGNvdW50IGlzIGluY3JlYXNlZCBleHBs
aWNpdGx5IGF0IHRoaXMgcG9pbnQsDQoJCS8vIHRoZSBwcm9ncmFtIGZpbmlzaGVzIHdpdGhvdXQg
ZXJyb3I6DQoJCTo6Y2xSZXRhaW5Db250ZXh0KGNvbnRleHQyKCkpOw0KI2VuZGlmDQoNCgkJY291
dCA8PCAicmVmIGNvdW50ID0gIiA8PCBjb250ZXh0LmdldEluZm88Q0xfQ09OVEVYVF9SRUZFUkVO
Q0VfQ09VTlQ+KCkgPDwgZW5kbDsNCgl9DQoJY2F0Y2goY2w6OkVycm9yIGVycikgew0KCQljZXJy
IDw8ICJFUlJPUjogIiA8PCBlcnIud2hhdCgpIDw8ICIoIiA8PCBlcnIuZXJyKCkgPDwgIikiIDw8
IGVuZGw7DQoJfQ0KDQoJcmV0dXJuIEVYSVRfU1VDQ0VTUzsNCn0NCg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>41</attachid>
            <date>2010-05-03 11:38:00 -0700</date>
            <delta_ts>2010-05-03 11:38:03 -0700</delta_ts>
            <desc>proposed patch for reference counting bug</desc>
            <filename>cl.hpp.patch</filename>
            <type>text/plain</type>
            <size>1641</size>
            <attacher>markus.grabner</attacher>
            
              <data encoding="base64">LS0tIFI6L0FUSSBTdHJlYW0vaW5jbHVkZS9DTC9jbC0xLjAuaHBwCVRodSBBcHIgMjkgMTE6NDY6
NTcgMjAxMA0KKysrIFI6L0FUSSBTdHJlYW0vaW5jbHVkZS9DTC9jbC5ocHAJTW9uIE1heSAwMyAx
ODozMDo1MiAyMDEwDQpAQCAtMzM1LDYgKzMzNSw5IEBADQogY2xhc3MgQ29udGV4dDsNCiBjbGFz
cyBDb21tYW5kUXVldWU7DQogY2xhc3MgTWVtb3J5Ow0KK2NsYXNzIFNhbXBsZXI7DQorY2xhc3Mg
S2VybmVsOw0KK2NsYXNzIEV2ZW50Ow0KIA0KICNpZiBkZWZpbmVkKF9fQ0xfRU5BQkxFX0VYQ0VQ
VElPTlMpDQogI2luY2x1ZGUgPGV4Y2VwdGlvbj4NCkBAIC04MjQsNyArODI3LDkgQEANCiAgICAg
c3RhdGljIGNsX2ludA0KICAgICBnZXQoRnVuY3RvciBmLCBjbF91aW50IG5hbWUsIFQqIHBhcmFt
KQ0KICAgICB7DQotICAgICAgICByZXR1cm4gZihuYW1lLCBzaXplb2YoVCksIHBhcmFtLCBOVUxM
KTsNCisgICAgICAgIGNsX2ludCByZXQgPSBmKG5hbWUsIHNpemVvZihUKSwgcGFyYW0sIE5VTEwp
Ow0KKwkJZml4UmVmZXJlbmNlQ291bnQocGFyYW0pOw0KKwkJcmV0dXJuIHJldDsNCiAgICAgfQ0K
IH07DQogDQpAQCAtMTIxNiw2ICsxMjIxLDE0IEBADQogICAgIHsNCiAgICAgICAgIHJldHVybiBS
ZWZlcmVuY2VIYW5kbGVyPGNsX3R5cGU+OjpyZWxlYXNlKG9iamVjdF8pOw0KICAgICB9DQorDQor
CWZyaWVuZCB2b2lkIGZpeFJlZmVyZW5jZUNvdW50KENvbnRleHQgKnBhcmFtK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