-
Notifications
You must be signed in to change notification settings - Fork 111
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
Bug: Non of methods are working in Multi-threaded envirionment #441
Comments
You are probably doing something wrong, but I can't guess without code 🤗 |
Please run this code to see error. Without lock, it throw Access violation exception. `
} |
@etempm, can you limit the number of threads to a value smaller or equal to the number of physical cores on your machine? I suspect that's the issue. |
Yes, you are right!. I limited thread count to Environment.ProcessorCount and it worked like a charm. Thank you very much!!! |
Just for clarification. I will use usearch for real time face recognition over 100 ip cameras. Each camera working on own thread. With the 16 core cpu, 100 threads, real time. I can not limit thread count in thar situation. Will this be same problem? What is you opinion? |
For that we need to extend the "reserve" interface in C#, to allow optional second argument for the number of thread-specific "contexts" it can use. Then everything would work fine. Can you try patching the library to do that? |
If i can understand what you mean, i wil be glad to do that. I see extend method in native class which is increase capacity in c#. But i did not understand "thread specific context". C# code just calling your dll. Is your reserve method has that "context" parameter already? Can you tell more details . |
Ok, i am looking c code now. As i can see, a lot of functionality is missing on c# side. I can add that functions to c# wrapper. If you can add thread specific context parameter also, i will patch it too. |
So the C++ layer has a "reserve" function, which returns a structure - not just an integer. In that structure you can inform the number of threads that will use the index. For every one of those I pre-allocate queues and other buffers to avoid doing that during concurrent calls. That functionality is what we want to expose to C# users 🤗 Thanks to you too! |
I think you mean struct index_limits_t {
}; |
Hi, sory, I am not cpp guy. Trying to call function. I defined struct as: [StructLayout(LayoutKind.Sequential)] I added this function to NativeMethods [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] and called the method like this: IndexLimitsT limits2 = new IndexLimitsT bu no luck. Any idea? |
Describe the bug
I tried each of Add, Remove, Save and Search methods independently from each others with multiple threads. All of them are failed. Memory corruption error raised.
Steps to reproduce
You can run any of this methods in multiple threads to see error.
Expected behavior
At least, thread safe Search method is required. I am using locking to overcome this, but it is very slow.
USearch version
2.12.0
Operating System
Windows 11
Hardware architecture
x86
Which interface are you using?
Other bindings
Contact Details
[email protected]
Are you open to being tagged as a contributor?
.git
history as a contributorIs there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: