I am using gcc 2.95.3 to support a legacy system that uses multi-threaded application. STL implementation for basic_string is not threadsafe and STL implementation for __default_alloc_template<false, 0>::allocate(unsigned int)
too. If I could ovverride these by providing my own implementation that would ensure mutual exclusion through semaphore lock and unlock, and call the original function through dlsym
search?
Asked
Active
Viewed 170 times
0

Dr. Debasish Jana
- 6,980
- 4
- 30
- 69
-
It's a little confusing what the exact question is. If you provide your own implementation of string then what, will it be thread safe? Is it worth the effort? – UKMonkey Dec 01 '17 at 13:53
-
@Ron did you know that the stl fights in the bar with anyone that inherits from it? (c) – UKMonkey Dec 01 '17 at 13:54
-
1[`std::basic_string`](http://en.cppreference.com/w/cpp/string/basic_string) allows you to provide a custom allocator as a template argument. You can use this to provide a thread-safe allocator. `std::basic_string` is not designed to be thread safe however. In any case, you will need to provide your own synchronization. – François Andrieux Dec 01 '17 at 14:06
-
@FrançoisAndrieux when std::string is used, that, in turn, std::basic_string, how and where to pass the custom allocator? If I could pass custom thread-safe allocator, that would serve my purpose, please guide – Dr. Debasish Jana Dec 03 '17 at 14:28
-
@FrançoisAndrieux I was reading https://stackoverflow.com/questions/24658341/using-a-custom-allocator-in-stdstring-to-re-use-an-already-allocated-char-buff, it says std::string cannot be made use a different allocator, is there any way? – Dr. Debasish Jana Dec 03 '17 at 14:46
-
@Dr.DebasishJana No, you can't change the allocator is you are using `std::string` already. You would have to use `std::basic_string`. `std::string` *is* a `std::basic_string`, so the interface is identical. However, you would need to change ever instance of the type `std::string`. – François Andrieux Dec 04 '17 at 14:34
-
@FrançoisAndrieux how to override basic_string's allocator and use? – Dr. Debasish Jana Dec 06 '17 at 04:16