[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #RNK-564883]: NetCDF libraries threadsafe?



> Is the NetCDF 3.6.2  C library threadsafe? I received an unexpected
> "Not a valid ID" error in threading contexts and have been unable to
> find a definitive description of what is and isn't threadsafe in
> these libraries.
> 

My understanding is that it is NOT threadsafe.

I suspect it would not take all that much effort to make it threadsafe. If you 
would like to make it threadsafe we would very gratefully take that and add it 
to the release...

> I've found a couple posts to the contrary, but I also found a
> description of the NetCDF format as "Sharable. One writer and
> multiple readers may simultaneously access the same netCDF file."

This refers to different processes reading the same file, not different threads 
making library calls. The library maintains information on open files. If 
multiple threads are making calls, then this information will change in an 
unpredictable way.

> 
> If the NetCDF libraries are halfway threadsafe, I'd appreciate a
> description of what should/can't be done in threaded contexts.
> Perhaps this could be added to the FAQ section of the site?

I wish I could provide that description, but I do not know the answer.

However, you have the code and it is quite small really. So just take a look.

But I would think that not much could be done in a threadsafe way. Since the 
file's metadata is stored in memory, and since data buffers are used for all 
read operations, it's hard to see what two threads could safely do with the 
file. (Run nc_inq_ functions, perhaps, but that's probably not very useful.)

Hopefully I have got this correct, I will CC another netCDF programmer, Russ 
Rew, to be sure...

Thanks,

Ed

Ticket Details
===================
Ticket ID: RNK-564883
Department: Support netCDF
Priority: Normal
Status: Closed