Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNet: Static variables in DLL

Tags:

c

c#

.net

static

dll

I am working on a Dot Net project, which includes a DLL. This DLL uses a .lib (C code). Unfortunately, there are many static variables in this .lib. The Problem I have here:

If two users perform a search at the same time, I get an error, because they both access the .lib, one changes something while to other tries to read data.

The obvious solution, would be to lock the access, but I really don't want to do that, because that slows the search process down drastically. I would rather try to make a DLL from the lib, but I don't know if this would solve the problem, as I don't know if the static variables will then be stored separately, or if both search processes will access the same variables.

Does anyone have experience with this? Because it will take quite an amount of time to do this, and I'd like to know if it works before I start to do this.

I hope everything is understandable, as English is not my first language, and my programming skills are pretty basic.

like image 897
Stefan Avatar asked Nov 12 '22 23:11

Stefan


1 Answers

From what I understand, there is no way you are going to be able to simulataniously edit the data while you are reading from it using the existing classes within this .dll. Clearly this will just not work, no matter what fancy stuff you are doing.

What you could do is create a Thunking Layer. This will be a type of wrapper class that will be called instead of the .dll. This class will handle concurrent I/O requests by holding a local copy of the data for reads, and allowing smultanious edits to the real data, updating the local copy when these manipulations are finished (with appropriate temporary locking etc.). There may be other standard ways of doing this that I not aware of, but this is how I would start.

I hope this helps.

like image 199
MoonKnight Avatar answered Nov 15 '22 12:11

MoonKnight