Is a Delphi global procedure threadsafe

不羁岁月 提交于 2020-01-02 04:06:46

问题


If two or more threads call a standard Delphi/Pascal procedure (not a method of an object), is this threadsafe ? There is no instance data, just local variables in the procedure.
My guess is that the local storage being used by one thread could be corrupted by the other thread.


回答1:


Local storage is maintained on the stack, which is unique to each thread. If no global data is being manipulated by the routine, it is safe.




回答2:


if only local vars you should be ok. if I were you I would test that theory: declare a local variable in the proc and increment it a million time in a loop, then call the proc from two threads and check the value of the variable after the million increments.



来源:https://stackoverflow.com/questions/22083420/is-a-delphi-global-procedure-threadsafe

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