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)


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?

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.

-- 
Pekka

------------------------------------------------------------------------------
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

Reply via email to