# thread safe work in windows for a hdf static?

**URL:** <https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886>\
**Category:** Hdf-forum archives\
**Created:** [October 3, 2016, 6:59pm UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886 "2016-10-03T18:59:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaac\_gerg](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@Isaac\_gerg](https://forum.hdfgroup.org/u/Isaac_gerg)\
**Post date:** [October 3, 2016, 6:59pm UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886/1 "2016-10-03T18:59:46Z")

</div>

I see in the docs that as of 1.8.6 hdf threadsafe is available for windows  
but only if you use link hdf shared. Is this true with 1.8.17 (or the  
latest hdf version)?

Is thread safe available for hdf static in windows?

Thanks,  
isaac

---

<div class="post-metadata">

**Author:** ![werner](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@werner](https://forum.hdfgroup.org/u/werner)\
**Post date:** [October 4, 2016, 6:49am UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886/2 "2016-10-04T06:49:59Z")

</div>

Hi Isaac,

&nbsp;&nbsp;as far as I know the problem with static libraries is not the threadsafety of HDF5 itself, the code is the same, but the initialization & cleanup code. With a shared library, there are such defined entry points when loading and unloading a shared library which does a clean initialization and cleanup, but with a static library there is no such option. If you'd want to use threadsafe HDF5 with the static library, you would need to explicitly call the initialization & cleanup, for instance from your main program or from another shared library at startup/cleanup. I'm not sure whether HDF5 1.8.17 explicitly supports such, it may be possible but not implemented that way.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Werner

> **···**
>
> On 03.10.2016 20:59, Isaac Gerg wrote:
> 
> > I see in the docs that as of 1.8.6 hdf threadsafe is available for windows but only if you use link hdf shared. Is this true with 1.8.17 (or the latest hdf version)?
> > 
> > Is thread safe available for hdf static in windows?
> > 
> > Thanks,  
> > isaac
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)  
> > Twitter: [x.com](https://twitter.com/hdf5)
> 
> --  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Dr. Werner Benger Visualization Research  
> Center for Computation & Technology at Louisiana State University (CCT/LSU)  
> 2019 Digital Media Center, Baton Rouge, Louisiana 70803  
> Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

---

<div class="post-metadata">

**Author:** ![derobins](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/derobins/32/1481_2.png) [@derobins](https://forum.hdfgroup.org/u/derobins)\
**Post date:** [October 4, 2016, 9:06am UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886/3 "2016-10-04T09:06:32Z")

</div>

Hi all,

Werner is correct. You could build the thread-safe + static library with ALLOW\_UNSUPPORTED (under the advanced options if you use ccmake) and implement the thread attach/detach code yourself. You can check out the code in DllMain() at the end of src/H5.c to see what we do, which is actually quite minimal. Basically, you just have to initialize and clean up thread-local storage when you attach and detach threads, respectively.

Cheers,

Dana Robinson  
Software Engineer  
The HDF Group

> **···**
>
> From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Werner Benger  
> Sent: Tuesday, October 4, 2016 2:50 AM  
> To: hdf-forum@lists.hdfgroup.org  
> Subject: Re: [Hdf-forum] thread safe work in windows for a hdf static?
> 
> Hi Isaac,
> 
> as far as I know the problem with static libraries is not the threadsafety of HDF5 itself, the code is the same, but the initialization & cleanup code. With a shared library, there are such defined entry points when loading and unloading a shared library which does a clean initialization and cleanup, but with a static library there is no such option. If you'd want to use threadsafe HDF5 with the static library, you would need to explicitly call the initialization & cleanup, for instance from your main program or from another shared library at startup/cleanup. I'm not sure whether HDF5 1.8.17 explicitly supports such, it may be possible but not implemented that way.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Werner
> 
> On 03.10.2016 20:59, Isaac Gerg wrote:  
> I see in the docs that as of 1.8.6 hdf threadsafe is available for windows but only if you use link hdf shared. Is this true with 1.8.17 (or the latest hdf version)?
> 
> Is thread safe available for hdf static in windows?
> 
> Thanks,  
> isaac
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> 
> Hdf-forum is for HDF software users discussion.
> 
> Hdf-forum@lists.hdfgroup.org\<mailto:Hdf-forum@lists.hdfgroup.org\>
> 
> [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> Twitter: [https://twitter.com/hdf5](https://twitter.com/hdf5)
> 
> --
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> 
> Dr. Werner Benger Visualization Research
> 
> Center for Computation & Technology at Louisiana State University (CCT/LSU)
> 
> 2019 Digital Media Center, Baton Rouge, Louisiana 70803
> 
> Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

---

<div class="post-metadata">

**Author:** ![Isaac\_gerg](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@Isaac\_gerg](https://forum.hdfgroup.org/u/Isaac_gerg)\
**Post date:** [October 4, 2016, 1:41pm UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886/4 "2016-10-04T13:41:53Z")

</div>

Thank you all.

Just to be clear, is the native shared lib built with threadsafe?

> **···**
>
> On Tue, Oct 4, 2016 at 5:06 AM, Dana Robinson \<derobins@hdfgroup.org\> wrote:
> 
> > Hi all,
> > 
> > Werner is correct. You could build the thread-safe + static library with  
> > ALLOW\_UNSUPPORTED (under the advanced options if you use ccmake) and  
> > implement the thread attach/detach code yourself. You can check out the  
> > code in DllMain() at the end of src/H5.c to see what we do, which is  
> > actually quite minimal. Basically, you just have to initialize and clean up  
> > thread-local storage when you attach and detach threads, respectively.
> > 
> > Cheers,
> > 
> > Dana Robinson
> > 
> > Software Engineer
> > 
> > The HDF Group
> > 
> > \*From:\* Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] \*On  
> > Behalf Of \*Werner Benger  
> > \*Sent:\* Tuesday, October 4, 2016 2:50 AM  
> > \*To:\* hdf-forum@lists.hdfgroup.org  
> > \*Subject:\* Re: [Hdf-forum] thread safe work in windows for a hdf static?
> > 
> > Hi Isaac,
> > 
> > as far as I know the problem with static libraries is not the  
> > threadsafety of HDF5 itself, the code is the same, but the initialization &  
> > cleanup code. With a shared library, there are such defined entry points  
> > when loading and unloading a shared library which does a clean  
> > initialization and cleanup, but with a static library there is no such  
> > option. If you'd want to use threadsafe HDF5 with the static library, you  
> > would need to explicitly call the initialization & cleanup, for instance  
> > from your main program or from another shared library at startup/cleanup.  
> > I'm not sure whether HDF5 1.8.17 explicitly supports such, it may be  
> > possible but not implemented that way.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Werner
> > 
> > On 03.10.2016 20:59, Isaac Gerg wrote:
> > 
> > I see in the docs that as of 1.8.6 hdf threadsafe is available for windows  
> > but only if you use link hdf shared. Is this true with 1.8.17 (or the  
> > latest hdf version)?
> > 
> > Is thread safe available for hdf static in windows?
> > 
> > Thanks,
> > 
> > isaac
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> > 
> > Hdf-forum is for HDF software users discussion.
> > 
> > Hdf-forum@lists.hdfgroup.org
> > 
> > [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> > 
> > Twitter: [x.com](https://twitter.com/hdf5)
> > 
> > --
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> > 
> > Dr. Werner Benger Visualization Research
> > 
> > Center for Computation & Technology at Louisiana State University (CCT/LSU)
> > 
> > 2019 Digital Media Center, Baton Rouge, Louisiana 70803
> > 
> > Tel.: +1 225 578 4809 Fax.: +1 225 578-5362
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Hdf-forum is for HDF software users discussion.  
> > Hdf-forum@lists.hdfgroup.org  
> > [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)  
> > Twitter: [x.com](https://twitter.com/hdf5)

---

<div class="post-metadata">

**Author:** ![derobins](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/derobins/32/1481_2.png) [@derobins](https://forum.hdfgroup.org/u/derobins)\
**Post date:** [October 4, 2016, 2:00pm UTC](https://forum.hdfgroup.org/t/thread-safe-work-in-windows-for-a-hdf-static/3886/5 "2016-10-04T14:00:52Z")

</div>

Not by default. The locking scheme has overhead so it's not enabled unless you ask for it.

Dana

> **···**
>
> From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Isaac Gerg  
> Sent: Tuesday, October 4, 2016 9:42 AM  
> To: HDF Users Discussion List \<hdf-forum@lists.hdfgroup.org\>  
> Subject: Re: [Hdf-forum] thread safe work in windows for a hdf static?
> 
> Thank you all.
> 
> Just to be clear, is the native shared lib built with threadsafe?
> 
> On Tue, Oct 4, 2016 at 5:06 AM, Dana Robinson \<derobins@hdfgroup.org\<mailto:derobins@hdfgroup.org\>\> wrote:  
> Hi all,
> 
> Werner is correct. You could build the thread-safe + static library with ALLOW\_UNSUPPORTED (under the advanced options if you use ccmake) and implement the thread attach/detach code yourself. You can check out the code in DllMain() at the end of src/H5.c to see what we do, which is actually quite minimal. Basically, you just have to initialize and clean up thread-local storage when you attach and detach threads, respectively.
> 
> Cheers,
> 
> Dana Robinson  
> Software Engineer  
> The HDF Group
> 
> From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org\<mailto:hdf-forum-bounces@lists.hdfgroup.org\>] On Behalf Of Werner Benger  
> Sent: Tuesday, October 4, 2016 2:50 AM  
> To: hdf-forum@lists.hdfgroup.org\<mailto:hdf-forum@lists.hdfgroup.org\>  
> Subject: Re: [Hdf-forum] thread safe work in windows for a hdf static?
> 
> Hi Isaac,
> 
> as far as I know the problem with static libraries is not the threadsafety of HDF5 itself, the code is the same, but the initialization & cleanup code. With a shared library, there are such defined entry points when loading and unloading a shared library which does a clean initialization and cleanup, but with a static library there is no such option. If you'd want to use threadsafe HDF5 with the static library, you would need to explicitly call the initialization & cleanup, for instance from your main program or from another shared library at startup/cleanup. I'm not sure whether HDF5 1.8.17 explicitly supports such, it may be possible but not implemented that way.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Werner
> 
> On 03.10.2016 20:59, Isaac Gerg wrote:  
> I see in the docs that as of 1.8.6 hdf threadsafe is available for windows but only if you use link hdf shared. Is this true with 1.8.17 (or the latest hdf version)?
> 
> Is thread safe available for hdf static in windows?
> 
> Thanks,  
> isaac
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> 
> Hdf-forum is for HDF software users discussion.
> 
> Hdf-forum@lists.hdfgroup.org\<mailto:Hdf-forum@lists.hdfgroup.org\>
> 
> [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)
> 
> Twitter: [https://twitter.com/hdf5](https://twitter.com/hdf5)
> 
> --
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
> 
> Dr. Werner Benger Visualization Research
> 
> Center for Computation & Technology at Louisiana State University (CCT/LSU)
> 
> 2019 Digital Media Center, Baton Rouge, Louisiana 70803
> 
> Tel.: +1 225 578 4809\<tel:%2B1%20225%20578%204809\> Fax.: +1 225 578-5362\<tel:%2B1%20225%20578-5362\>
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Hdf-forum is for HDF software users discussion.  
> Hdf-forum@lists.hdfgroup.org\<mailto:Hdf-forum@lists.hdfgroup.org\>  
> [http://lists.hdfgroup.org/mailman/listinfo/hdf-forum\_lists.hdfgroup.org](http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org)  
> Twitter: [https://twitter.com/hdf5](https://twitter.com/hdf5)
