How can I implement a thread-safe list wrapper in Delphi?

巧了我就是萌 提交于 2019-12-01 17:39:30

You should have a look at the TMultiReadExclusiveWriteSynchronizer class declared in sysutils.pas...

Have a look at this tutorial. Threading the Delphi Way

Look at Chapter 11, but it's all good stuff.

You really should look at TThreadList.

The methods .Add, .Remove, .Clear automatically lock the list for you. If needed, you can also lock/unlock as needed:

x.LockList; 
try 
  //do whatever
finally  
  x.Unlocklist; 
end;

TMultiReadExclusiveWriteSynchronizer is a grand idea but I don't know if they ever ironed all the bugs out. It has always had issues under load.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!