-
Notifications
You must be signed in to change notification settings - Fork 1
Fix thread-safety: remove static from local variables #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix thread-safety: remove static from local variables #6
Conversation
The f2c-translated C code had static local variables in multiple functions (setulb_, mainlb_, and 18+ other subroutines), making them non-thread-safe. Static variables are shared across all function calls, causing race conditions, memory corruption, and segmentation faults in multi-threaded contexts. This commit removes the static keyword from 202 local variable declarations, making each function call have its own independent local state on the stack. Only legitimate static uses (constant definitions and format strings) are preserved. This enables true thread-safety without requiring mutex serialization.
Use the fixed version of lbfgsb_cpp that removes static local variables to enable true thread-safety. This eliminates the need for mutex serialization in the optimizer. Related PRs: - yannrichet/lbfgsb_cpp#3 - libKriging/lbfgsb_cpp#6
hpwxf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J’y jette un œil complémentaire asap.
| const int* iprint, char* csave, | ||
| bool* lsave, int* isave, double* dsave, | ||
| std::size_t len_task, std::size_t len_csave | ||
| ftnlen len_task, ftnlen len_csave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dans quel cas as-tu besoin de changer le type associé à la taille ?
| namespace lbfgsb { | ||
| extern "C" { | ||
| void setulb_( | ||
| int setulb_( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D’où vient le besoin du retour en int ?
| "\002,/,\002 2 rounding errors dominate computat" | ||
| "ion.\002)"; | ||
| static char fmt_9015[] = "(/,\002 Warning: more than 10 function and gr" | ||
| char fmt_9015[] = "(/,\002 Warning: more than 10 function and gr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J’ai l’impression que beaucoup de variables statiques avec une telle valeur par défaut pourraient être passées en « static const » ou juste « const » (meilleur pour les perfs et la safety)
|
Désolé, c'est l'autre PR qu'il faut regarder :) |
The f2c-translated C code had static local variables in multiple functions (setulb_, mainlb_, and 18+ other subroutines), making them non-thread-safe.
Static variables are shared across all function calls, causing race conditions, memory corruption, and segmentation faults in multi-threaded contexts.
This commit removes the static keyword from 202 local variable declarations, making each function call have its own independent local state on the stack. Only legitimate static uses (constant definitions and format strings) are preserved.
This enables true thread-safety without requiring mutex serialization.
Testing:
Related: