Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Dennis Jones
Fri, 12 Jan 2007 17:51
Is this Indy code safe?
Author: Dennis Jones
Date: Fri, 12 Jan 2007 17:51
Date: Fri, 12 Jan 2007 17:51
19 lines
1544 bytes
1544 bytes
Hello,
Is the following code (from Indy 9) safe, or is it possible for the
TCPServer->Threads 'Count' to change between the LockList() and UnlockList()
calls? (this code is in a message handler function that is called as the
result of a PostMessage, so it runs in the context of the main thread)
TList *pThreadList = TCPServer->Threads->LockList();
int Count = pThreadList->Count;
for ( int c=0; c<Count; ++c )
{
TIdPeerThread *pPeerThread = static_cast<TIdPeerThread
*>(pThreadList->Items[c]);
// do something with the thread
}
TCPServer->Threads->UnlockList();
- Dennis
Re: Is this Indy code safe?
Author: Remy Lebeau (TeamB)
Date: Fri, 12 Jan 2007 19:40
Date: Fri, 12 Jan 2007 19:40
18 lines
1406 bytes
1406 bytes
"Dennis Jones" <nospam@nospam.com> wrote in message news:45a7ca99$1@newsgroups.borland.com... > Is the following code (from Indy 9) safe Asside from a missing handler to ensure UnlockList() is always called regardless of an exception being thrown, then yes, it is generally safe. > is it possible for the TCPServer->Threads 'Count' to > change between the LockList() and UnlockList() calls? It is not possible. The list is locked and will not allow external changes until it is unlocked. Gambit
Re: Is this Indy code safe?
Author: Dennis Jones
Date: Fri, 12 Jan 2007 20:13
Date: Fri, 12 Jan 2007 20:13
24 lines
1751 bytes
1751 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:45a7e43c$1@newsgroups.borland.com... > > "Dennis Jones" <nospam@nospam.com> wrote in message > news:45a7ca99$1@newsgroups.borland.com... > >> Is the following code (from Indy 9) safe > > Asside from a missing handler to ensure UnlockList() is always called > regardless of an exception being thrown, then yes, it is generally > safe. Ah, yes, thank you. I've added an RAII object to handle that for me. >> is it possible for the TCPServer->Threads 'Count' to >> change between the LockList() and UnlockList() calls? > > It is not possible. The list is locked and will not allow external > changes until it is unlocked. Thanks, I suspected that was the case, but wasn't certain. - Dennis
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads