GetThreadID or GetCurrentThreadID lazarus / 62-General ---------------------------------------------------------------------- Douglas Medeiros · 2016-03-14 17:29 Hello, I`m working in a creation of a specific  rest web server. I am using synapse  framework to create a Http server. My server is thread safe, and worked very well in previews tests. In my project I am using my own dependency inject framework, but I need do some improvements on this framework. Today, he has some limitations to work well with threads and I want remove this limitations. But I found a problem when I used GetThreadID or GetCurrentThreadID. Both returns the same code (threadID), doesn't matter if I call in deferents threads.  The number just change if a restart the application. But, every call (my application is a rest server) creates a new thread but I received the same result from GetThreadID or GetCurrentThreadID. My impression is: GetThreadID or GetCurrentThreadID returns the main thread id.  In my opinion when I call GetThreadID or GetCurrentThreadID, the result should be according the thread who called GetThreadID or GetCurrentThreadID. I am using Lazarus 1.4.2 (32 bits) and FPC 2.6.4 (32 bits), on Windows 8 64bits. It is my first topic here. If a made something wrong, please, tell me and I will correct it. There are some ideia about my problem? Below, I posted my method who uses GetThreadID: {   Should be one container for every thread. } function TInjector.GetContainer: IContainer; var   LocalContainer : IContainer; begin   LocalContainer := nil;   // Check if exists a container to current thread.   for LocalContainer in FContainerList do   begin     if LocalContainer.GetThreadID = GetThreadID then     begin       Result := LocalContainer;       Exit;     end;   end;   // If a container was not found, create a copy from a original container.  // This copy will be used just for de current thread.   if LocalContainer = nil then   begin     LocalContainer := FContainer.Copy;     FContainerList.Add(LocalContainer);   end;   Result := LocalContainer; end; ---------------------------------------------------------------------- taazz · 2016-03-14 18:15 Sorry but if the GetCurrentThreadId procedure always returns the application's thread ID then your code is executed inside the main application thread and not in a separate thread. ---------------------------------------------------------------------- Douglas Medeiros · 2016-03-15 13:18 Yes you are right. I was calling my method from destroy method of my thread. Of corse destroy method of  a Thread is not in a Thread. Thank you.