Le 11/01/2013 09:32, Pekka Jääskeläinen a écrit :
> On 01/11/2013 10:21 AM, GuWangfeng wrote:
>> If the object's pocl_refcount is 1 and then two threads call
>> clReleaseXXX(object) at the same time, the object's
>> pocl_refcount may be decremented twice and becomes -1. The object
>> doesn't have any chance to be destructed!
>>
>> Is my thought wrong?
>
> The refcount decrement itself is protected by locks, thus should
> be thread safe.
>
> pocl_cl.h:
>
> #define POCL_RELEASE_OBJECT(__OBJ__) \
> do { \
> POCL_LOCK_OBJ (__OBJ__); \
> (__OBJ__)->pocl_refcount--; \
> POCL_UNLOCK_OBJ (__OBJ__); \
> } while (0)
>
> #define POCL_RETAIN_OBJECT(__OBJ__) \
> do { \
> POCL_LOCK_OBJ (__OBJ__); \
> (__OBJ__)->pocl_refcount++; \
> POCL_UNLOCK_OBJ (__OBJ__); \
> } while (0)
For such simple task, an atomic operation when available would be
far more efficient (new __atomic... or old __sync... operations of
gcc to avoid to code assembly for each processor)
> If your two threads release the same object "handle" more times than they
> have called the retain functions, it is a bug in your OpenCL application,
> isn't it?
I agree.
If the lock is extented to include the test that release the data,
you will then always release the data. But the final refcount will still
be -1, something that indicate a bug from my point of view.
Regards,
Vincent
> However, as the thread-safety of the host API implementation hasn't been
> tested so much, I wouldn't be surprised if you find mutual exclusion
> bugs from the other parts. Reporting or even fixing them would be appreciated.
>
--
Vincent Danjean Adresse: Laboratoire d'Informatique de Grenoble
Téléphone: +33 4 76 61 20 11 ENSIMAG - antenne de Montbonnot
Fax: +33 4 76 61 20 99 ZIRST 51, avenue Jean Kuntzmann
Email: [email protected] 38330 Montbonnot Saint Martin
------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
pocl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pocl-devel