RSE
RSE

Reputation: 322

Is it safe to instantiate a TThread-descendent from inside a thread?

I have a task where I have to do some heavy CPU/RAM stuff to do. With the outcome of that, I have to do some database requests. All of this I have to do for some thousand times, so I'm doing it inside a background thread. Now I'm considering dividing each task up into the two parts and split them between 2 separate threads, so that the first thread don't have to wait for the database requests to finish. It then could do the CPU/RAM stuff for the second round while the second thread is waiting for the database requests of the first round and everything would speed up.

Now, is it safe to instantiate the second TThread descendent from within the first one? Or do I need to instantiate TThread descendents from within MainThread? I could do both, but instantiating the second from within the first would be easier in my case, and it would be following the oop paradigm as the second thread would be transparent to the rest of the program.

Upvotes: 1

Views: 218

Answers (1)

mg30rg
mg30rg

Reputation: 1349

I did it lots of times in production code and it never was a real issue. I can say it seems to be perfectly safe.

Upvotes: 4

Related Questions