Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an old C codebase with many globals reentrant

I'm working with a large, old C codebase (an interpreter) that uses global variables a great deal, with the result that I cannot have two instances of it at once. Is there a straightforward (ideally automated) approach to convert this code to something reentrant? i.e. some refactor tool that would make all globals part of a struct and prepend the pointer to all variables?

Could I convert to C++ and wrap the entire thing in a class definition?

like image 319
user1043479 Avatar asked Feb 03 '26 18:02

user1043479


1 Answers

I would recommend to convert your project into C++11 project and change all your static vars into threadlocal.

This can be up to several days of work depending on the size of your project. In certain cases this will work.

like image 172
Kirill Kobelev Avatar answered Feb 05 '26 08:02

Kirill Kobelev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!