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.
Asked
Active
Viewed 765 times
5

David Moorhouse
- 1,573
- 3
- 14
- 19
-
Local vars are put onto the stack, that's right, except for things like long strings which need additionally dynamically allocated memory => Are you sure your MM runs in multithread mode? And could you provide an http://sscce.org? – JensG Feb 28 '14 at 00:45
-
It also depends on the functions that your global function calls. An concrete example would help. – David Heffernan Feb 28 '14 at 03:35
2 Answers
9
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.

Mason Wheeler
- 82,511
- 50
- 270
- 477
0
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.

Z .
- 12,657
- 1
- 31
- 56
-
1Experiment cannot prove thread safety. It's a valuable test, but thread safety has to be reasoned about statically. – David Heffernan Feb 28 '14 at 04:32