thread safety #128

Closed
opened 2017-09-07 15:13:47 +00:00 by karen-arutyunov · 3 comments
karen-arutyunov commented 2017-09-07 15:13:47 +00:00 (Migrated from github.com)

Hello,

We are considering usage of libpkgconf in our build2 toolchain project, but got some concerns regarding thread safety of the library.

The documentation implies thread safety if client objects are not shared across thread boundaries. Meanwhile looking into the code it seems that's not always the case. For example get_default_pkgconfig_path() function uses static variable outbuf which effectively makes it thread-unsafe, and so pkgconf_pkg_dir_list_build() that use it becomes thread-unsafe also. Another example is pkgconf_tuple_parse() which also uses static variable varname making unsafe itself, as well as other functions that use it directly or indirectly, in particular pkgconf_pkg_find(). In the later case it is not quite clear why the variable is made static. Actually there are quite a few places where such a static buffers are used (just grep for 'static char') and can potentially be an issue.

Am I missing something, or misread the documentation and the library is not thread-safe by design? Are there any plans to change this if so?

Thanks,
Karen

Hello, We are considering usage of libpkgconf in our build2 toolchain project, but got some concerns regarding thread safety of the library. The documentation implies thread safety if client objects are not shared across thread boundaries. Meanwhile looking into the code it seems that's not always the case. For example get_default_pkgconfig_path() function uses static variable outbuf which effectively makes it thread-unsafe, and so pkgconf_pkg_dir_list_build() that use it becomes thread-unsafe also. Another example is pkgconf_tuple_parse() which also uses static variable varname making unsafe itself, as well as other functions that use it directly or indirectly, in particular pkgconf_pkg_find(). In the later case it is not quite clear why the variable is made static. Actually there are quite a few places where such a static buffers are used (just grep for 'static char') and can potentially be an issue. Am I missing something, or misread the documentation and the library is not thread-safe by design? Are there any plans to change this if so? Thanks, Karen

hi,

right now there are still some parts of the library that are not purely thread safe. the library and original pkgconf tool were not built around a threaded design, so thread safety wasn't a concern.

reducing the use of scratch buffers is on the todo list for the 1.4 series, which would resolve most thread safety concerns -- but i would suggest only one thread access a pkgconf_client_t handle at a time, guarded by a mutex or similar synchronization mechanism.

hope that clarifies things...

hi, right now there are still some parts of the library that are not purely thread safe. the library and original pkgconf tool were not built around a threaded design, so thread safety wasn't a concern. reducing the use of scratch buffers is on the todo list for the 1.4 series, which would resolve most thread safety concerns -- but i would suggest only one thread access a `pkgconf_client_t` handle at a time, guarded by a mutex or similar synchronization mechanism. hope that clarifies things...
boris-kolpackov commented 2017-09-09 13:56:42 +00:00 (Migrated from github.com)

If the library is not (yet) thread-safe, shouldn't this issue remain open?

If the library is not (yet) thread-safe, shouldn't this issue remain open?

i closed it after removing the scratch buffers. sharing pkgconf_client_t between threads remains unsafe intentionally.

i closed it after removing the scratch buffers. sharing `pkgconf_client_t` between threads remains unsafe intentionally.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ariadne/pkgconf#128
There is no content yet.