Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sockets, threads, critical sections that are not..

Status
Not open for further replies.

Willeboer

Programmer
Feb 14, 2003
1
ZA
Hi

Just wondering if anyone has found the same problem. Quick outlay:

Create a thread. Inside the thread create a TServerSocket. In TServerSocket's OnRead event, at tbe beginning of the OnRead function, I put in a criticalsection->acquire, (the criticalsection is globally defined) to ensure only one socket read at a time is handled. Works lovely, but if 2 requests (reads) come in VERY close to each other, the acquire happens twice, before a release has been called.

I even put it all in a try .. finally, but before the lock is released, it is acquired. How I found out was to put a line of code writing to my logging area right after the acquire part. Quite strange to see "lock acquired", and right after that again "lock acquired".

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top