[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20050202: netCDF C++ - Why is static valiable used in NcVar::put function?
- Subject: Re: 20050202: netCDF C++ - Why is static valiable used in NcVar::put function?
- Date: Wed, 02 Feb 2005 10:24:55 -0700
>To: address@hidden
>From: "Masahiro Miiyaki" <address@hidden>
>Subject: netCDF C++ - Why is static variable used in NcVar::put function?
>Organization: WeatherNews Inc.
>Keywords: 200502021156.j12BuUFh022284 netCDF C++
Hi Masahiro Miiyaki,
> Inquiry: I am trying to be able to work the NetCDF library in multi
> thread environment.
>
> I have been almost finished the modification that the C library can
> work in multi thread.
>
> But I found the point which was harmful to multi thread environment in
> the netcdf.cpp file. Line number 807,
>
> static long start[5] = {0, 0, 0, 0, 0};
> for (int j = 0; j < 5; j++) {
> start[j] = the_cur[j];
> }
>
> Why is the static variable used in this macro?
There is no good reason, it looks like a mistake. If you delete the
"static" and the initialization to {0, 0, 0, 0, 0}, I think it will
still work as intended:
long start[5]; \
for (int j = 0; j < 5; j++) { \
start[j] = the_cur[j]; \
} \
Thanks for pointing out the error. Please let us know if this fix
works.
There may be other problems with trying to make the C library
thread-safe, since there are several global data structures, e.g. the
list of open netCDF files declared in libsrc/nc.c:
/* list of open netcdf's */
static NC *NClist = NULL;
Also, you should not expect to be able to do multiple concurrent
writes on the same open file.
I would be interested in whether you have success making it work for
multiple threads.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu/staff/russ