search->domainname = (char *) domainname;
search->category = category;
+ /* Since tfind/tsearch manage a balanced tree, concurrent tfind and
+ tsearch calls can be fatal. */
+ __libc_rwlock_define_initialized (static, tree_lock);
+ __libc_rwlock_rdlock (tree_lock);
+
foundp = (struct known_translation_t **) tfind (search, &root, transcmp);
+
+ __libc_rwlock_unlock (tree_lock);
+
freea (search);
if (foundp != NULL && (*foundp)->counter == _nl_msg_cat_cntr)
{
newp->translation = retval;
newp->translation_length = retlen;
+ __libc_rwlock_wrlock (tree_lock);
+
/* Insert the entry in the search tree. */
foundp = (struct known_translation_t **)
tsearch (newp, &root, transcmp);
+
+ __libc_rwlock_unlock (tree_lock);
+
if (foundp == NULL
|| __builtin_expect (*foundp != newp, 0))
/* The insert failed. */