EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ServerThread Thread Safe?

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#2809
Posted: 04/29/2007 16:41:00
by William Galloway (Standard support level)
Joined: 04/26/2007
Posts: 4

In your sftpserverdemo you create a thread for every connection. And assign local procedures for the thread to execute on certian events.

example:
TSSHServerThread(SocketThread).OnLog := ServerThreadLog;

Is this safe? I mean if 100 threads call this is there a problem because there is not locking or anything else inside the procedure? If it is then this is how I would be able to handle extended requests without putting the code into serverthread.pas. I could just do TSSHServerThread(SocketThread).OnExtendedCmd := mylocalformprocedure;

Thanks,
Will

#2810
Posted: 04/30/2007 00:02:54
by Ken Ivanov (EldoS Corp.)

Yes, all such calls are safe. All the necessary locking is done via corresponding Synchronize() calls inside TSSHServerThread class. For instance, please take a look at the implementation of TSSHServerThread.Log() method:
Code
procedure TSSHServerThread.Log(const S: string);
begin
  if Assigned(FOnLog) then
  begin
    FCurrLogLine := S;
    Synchronize(DoLog); // <--- the call is synchronized
  end;
end;


Quote
If it is then this is how I would be able to handle extended requests without putting the code into serverthread.pas.

It depends on how exactly extended requests are handled by the event handler. If the handler does not deal with form components (i.e., does not change labels, edit controls, listviews etc.) then you can avoid Synchronize() calls. However, if the event handler accesses form components or some other shared resources, you have to implement locking yourself.

Reply

Statistics

Topic viewed 1862 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!