List Info

Thread: cmsCreateTransform is not thread safe




cmsCreateTransform is not thread safe
user name
2007-06-05 01:13:47
Hi,
    cmsCreateTransform is not thread safe using 1.16 or
1.17b.  Note, using 
cmsCreate_sRGBProfile() instead of 
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
") does work, and so does 
calling the two cmsCreateTransform()'s in succession.  Test
env: 32bit debug 
target built with VS2005 on Vista64.

Louis Solomon
www.SteelBytes.com


#include <windows.h>
#include "lcmslcms.h"

static cmsHPROFILE prof_xyz,prof_rgb;
static cmsHTRANSFORM trans_xyz_to_rgb,trans_rgb_to_xyz;

static DWORD WINAPI make_trans_xyz_to_rgb(LPVOID
lpParameter)
{
 trans_xyz_to_rgb = cmsCreateTransform(
  prof_xyz,TYPE_XYZ_DBL,
  prof_rgb,TYPE_RGB_DBL,
  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
 return 0;
}

static DWORD WINAPI make_trans_rgb_to_xyz(LPVOID
lpParameter)
{
 trans_rgb_to_xyz = cmsCreateTransform(
  prof_rgb,TYPE_RGB_DBL,
  prof_xyz,TYPE_XYZ_DBL,
  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
 return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE
hPrevInstance,LPSTR 
lpCmdLine,int nCmdShow)
{
 prof_xyz = cmsCreateXYZProfile();
 prof_rgb =
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
"); 
//cmsCreate_sRGBProfile();
 for (int i=0;i<10;++i)
 {
#define try_threads
#ifdef try_threads
  DWORD threadid;
  HANDLE workers[2];
  workers[0] =
CreateThread(NULL,0,make_trans_xyz_to_rgb,NULL,0,&thread
id);
  workers[1] =
CreateThread(NULL,0,make_trans_rgb_to_xyz,NULL,0,&thread
id);
  WaitForMultipleObjects(2,workers,TRUE,INFINITE);
  for (unsigned i=0;i<2;++i)
   CloseHandle(workers[i]);
#else
  make_trans_xyz_to_rgb(0);
  make_trans_rgb_to_xyz(0);
#endif
  cmsDeleteTransform(trans_xyz_to_rgb);
  cmsDeleteTransform(trans_rgb_to_xyz);
 }
 cmsCloseProfile(prof_rgb);
 cmsCloseProfile(prof_xyz);
}


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Lcms-user mailing list
Lcms-userlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user


Re: cmsCreateTransform is not thread safe
country flaguser name
Spain
2007-06-07 03:08:16

Hi Louis,

Thanks for the report. Yes, you are right,
cmsCreateTransform
is not thread safe if the involved profiles are file-based.
That is
because files are not locked when readed. Currently, only
cmsDoTransform() is thread safe, and strictly you have to
turn on USE_PTHREADS toggle on lcms.h

That is so because multithreading only make real sense when
applying rerendering. But your point is well taken, and
locking the
file would be an interesting addition for next release,
unfortunately
not for 1.17 since I am already out of schedule.

Thanks again.
Marti

----- Original Message ----- 
From: "Louis Solomon [SteelBytes]" <louissteelbytes.com>
To: "lcms-user" <lcms-userlists.sourceforge.net>
Sent: Tuesday, June 05, 2007 8:13 AM
Subject: [Lcms-user] cmsCreateTransform is not thread safe


Hi,
    cmsCreateTransform is not thread safe using 1.16 or
1.17b.  Note, using
cmsCreate_sRGBProfile() instead of
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
") does work, and so does
calling the two cmsCreateTransform()'s in succession.  Test
env: 32bit debug
target built with VS2005 on Vista64.

Louis Solomon
www.SteelBytes.com


#include <windows.h>
#include "lcmslcms.h"

static cmsHPROFILE prof_xyz,prof_rgb;
static cmsHTRANSFORM trans_xyz_to_rgb,trans_rgb_to_xyz;

static DWORD WINAPI make_trans_xyz_to_rgb(LPVOID
lpParameter)
{
 trans_xyz_to_rgb = cmsCreateTransform(
  prof_xyz,TYPE_XYZ_DBL,
  prof_rgb,TYPE_RGB_DBL,
  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
 return 0;
}

static DWORD WINAPI make_trans_rgb_to_xyz(LPVOID
lpParameter)
{
 trans_rgb_to_xyz = cmsCreateTransform(
  prof_rgb,TYPE_RGB_DBL,
  prof_xyz,TYPE_XYZ_DBL,
  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
 return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE
hPrevInstance,LPSTR
lpCmdLine,int nCmdShow)
{
 prof_xyz = cmsCreateXYZProfile();
 prof_rgb =
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
");
//cmsCreate_sRGBProfile();
 for (int i=0;i<10;++i)
 {
#define try_threads
#ifdef try_threads
  DWORD threadid;
  HANDLE workers[2];
  workers[0] =
CreateThread(NULL,0,make_trans_xyz_to_rgb,NULL,0,&thread
id);
  workers[1] =
CreateThread(NULL,0,make_trans_rgb_to_xyz,NULL,0,&thread
id);
  WaitForMultipleObjects(2,workers,TRUE,INFINITE);
  for (unsigned i=0;i<2;++i)
   CloseHandle(workers[i]);
#else
  make_trans_xyz_to_rgb(0);
  make_trans_rgb_to_xyz(0);
#endif
  cmsDeleteTransform(trans_xyz_to_rgb);
  cmsDeleteTransform(trans_rgb_to_xyz);
 }
 cmsCloseProfile(prof_rgb);
 cmsCloseProfile(prof_xyz);
}


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Lcms-user mailing list
Lcms-userlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user




------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Lcms-user mailing list
Lcms-userlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user


Re: cmsCreateTransform is not thread safe
user name
2007-06-07 20:28:00
> not thread safe if the involved profiles are
file-based

it still crashes if I use USE_PTHREADS and
cmsOpenProfileFromMem()

my reason for wanting to do this, is that
cmsCreateTransform() can be quite 
slow (as much as 1sec), and I often want to make multiple
transforms.

note, if I use cmsCreate_sRGBProfile() instead of
cmsOpenProfileFromXXX(), 
it doesn't crash

Louis Solomon
www.SteelBytes.com

----- Original Message ----- 
From: "Marti.Maria" <marti.marialittlecms.com>
To: "Louis Solomon [SteelBytes]" <louissteelbytes.com>; "lcms-user"
<lcms-userlists.sourceforge.net>
Sent: Thursday, June 07, 2007 6:08 PM
Subject: Re: [Lcms-user] cmsCreateTransform is not thread
safe


>
>
> Hi Louis,
>
> Thanks for the report. Yes, you are right,
cmsCreateTransform
> is not thread safe if the involved profiles are
file-based. That is
> because files are not locked when readed. Currently,
only
> cmsDoTransform() is thread safe, and strictly you have
to
> turn on USE_PTHREADS toggle on lcms.h
>
> That is so because multithreading only make real sense
when
> applying rerendering. But your point is well taken, and
locking the
> file would be an interesting addition for next release,
unfortunately
> not for 1.17 since I am already out of schedule.
>
> Thanks again.
> Marti
>
> ----- Original Message ----- 
> From: "Louis Solomon [SteelBytes]"
<louissteelbytes.com>
> To: "lcms-user" <lcms-userlists.sourceforge.net>
> Sent: Tuesday, June 05, 2007 8:13 AM
> Subject: [Lcms-user] cmsCreateTransform is not thread
safe
>
>
> Hi,
>    cmsCreateTransform is not thread safe using 1.16 or
1.17b.  Note, using
> cmsCreate_sRGBProfile() instead of
>
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
") does work, and so does
> calling the two cmsCreateTransform()'s in succession. 
Test env: 32bit
> debug
> target built with VS2005 on Vista64.
>
> Louis Solomon
> www.SteelBytes.com
>
>
> #include <windows.h>
> #include "lcmslcms.h"
>
> static cmsHPROFILE prof_xyz,prof_rgb;
> static cmsHTRANSFORM
trans_xyz_to_rgb,trans_rgb_to_xyz;
>
> static DWORD WINAPI make_trans_xyz_to_rgb(LPVOID
lpParameter)
> {
> trans_xyz_to_rgb = cmsCreateTransform(
>  prof_xyz,TYPE_XYZ_DBL,
>  prof_rgb,TYPE_RGB_DBL,
>  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
> return 0;
> }
>
> static DWORD WINAPI make_trans_rgb_to_xyz(LPVOID
lpParameter)
> {
> trans_rgb_to_xyz = cmsCreateTransform(
>  prof_rgb,TYPE_RGB_DBL,
>  prof_xyz,TYPE_XYZ_DBL,
>  INTENT_ABSOLUTE_COLORIMETRIC,cmsFLAGS_NOTPRECALC);
> return 0;
> }
>
> int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE
hPrevInstance,LPSTR
> lpCmdLine,int nCmdShow)
> {
> prof_xyz = cmsCreateXYZProfile();
> prof_rgb =
cmsOpenProfileFromFile("AdobeRGB1998.icc","rb
");
> //cmsCreate_sRGBProfile();
> for (int i=0;i<10;++i)
> {
> #define try_threads
> #ifdef try_threads
>  DWORD threadid;
>  HANDLE workers[2];
>  workers[0] =
CreateThread(NULL,0,make_trans_xyz_to_rgb,NULL,0,&thread
id);
>  workers[1] =
CreateThread(NULL,0,make_trans_rgb_to_xyz,NULL,0,&thread
id);
>  WaitForMultipleObjects(2,workers,TRUE,INFINITE);
>  for (unsigned i=0;i<2;++i)
>   CloseHandle(workers[i]);
> #else
>  make_trans_xyz_to_rgb(0);
>  make_trans_rgb_to_xyz(0);
> #endif
>  cmsDeleteTransform(trans_xyz_to_rgb);
>  cmsDeleteTransform(trans_rgb_to_xyz);
> }
> cmsCloseProfile(prof_rgb);
> cmsCloseProfile(prof_xyz);
> }
>
>
>
------------------------------------------------------------
-------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2
express and take
> control of your XML. No limits. Just data. Click to get
it now.
> http://sourcefor
ge.net/powerbar/db2/
> _______________________________________________
> Lcms-user mailing list
> Lcms-userlists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lcms-user

>
>


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Lcms-user mailing list
Lcms-userlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user


Re: cmsCreateTransform is not thread safe
user name
2007-06-08 01:17:49
Would you try setting a mutex for cmsOpenProfileFromXXX().
With success 
this could be a solution for lcms. I would expect the slow
part in the 
computation of the transform, not in data i/o.

kind regards
Kai-Uwe Behrmann
--
developing for colour management 
www.behrmann.name + www.oyranos.org + www.cinepaint.org


Am 08.06.07, 11:28 +1000 schrieb Louis Solomon
[SteelBytes]:

> > not thread safe if the involved profiles are
file-based
> 
> it still crashes if I use USE_PTHREADS and
cmsOpenProfileFromMem()
> 
> my reason for wanting to do this, is that
cmsCreateTransform() can be quite 
> slow (as much as 1sec), and I often want to make
multiple transforms.
> 
> note, if I use cmsCreate_sRGBProfile() instead of
cmsOpenProfileFromXXX(), 
> it doesn't crash
> 
> Louis Solomon
> www.SteelBytes.com


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Lcms-user mailing list
Lcms-userlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )