Le 16/08/2019 à 17:11, James Richters a écrit :
Can I even do threads in a console program?
Yes, you can. I have in production some console code (worse: in a dll called by a console program written in 4gl (4js Genero www.4js.com)) with threads which compile unmodified under Linux and Windows.
By writing a descendant of TThread it's relatively easy to write a thread in FreePascal ( https://wiki.freepascal.org/Multithreaded_Application_Tutorial ). From your (non main) thread you can execute a procedure in the main thread by calling TThread.Synchronize.
From what I remember, the main problem in console is that you need to call regularly CheckSynchronize() ( from unit Classes ) from your program which run the main thread. That will be simpler for you, in my case, I had to export from my dll a pascal function calling CheckSynchronize() and call it regularly from the 4gl program with a timer ...
As far as I remember, it works just with a queue, when you call Synchronize you add a function call to the queue, and CheckSynchronize() read the queue and do the actual call of your function.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal