Skip to content
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

svm_train() in svmutil.py is not thread-safe #167

Open
wyykak opened this issue Apr 30, 2020 · 2 comments
Open

svm_train() in svmutil.py is not thread-safe #167

wyykak opened this issue Apr 30, 2020 · 2 comments

Comments

@wyykak
Copy link

wyykak commented Apr 30, 2020

To be more exact, svm_set_print_string_function() in svm.cpp is not thread-safe, as it modifies a global function pointer svm_print_string. If you call svm_train() in multiple Python threads with '-q' option, it will try to convert print_null() to a C-style function pointer and assign it to svm_print_string in order to suppress the output.

However, the function pointer generated each time seems to point to different addresses, which makes it possible to corrupt svm_print_string and crash the program.

I suggest to make the printing function pointer independent in different function calls. A global print option is neither thread-safe nor practical.

@cjlin1
Copy link
Owner

cjlin1 commented Apr 30, 2020 via email

@wyykak
Copy link
Author

wyykak commented Apr 30, 2020

Thanks for your reply!
In fact I have tried to use libsvm together with multiprocessing in Python, but SVM models, as C structs, cannot be serialized and tranferred between processes.
Currently libsvm only supports saving models as ascii files. Maybe you could add an interface to save models as strings? Therefore multiprocessing will be a possible way to parallelize libsvm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants