Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Socket and multiple Threads
Re: Socket and multiple Threads [message #27315 is a reply to message #27312] Mon, 12 July 2010 09:01 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13976
Registered: November 2005
Ultimate Member
Sc0rch wrote on Mon, 12 July 2010 02:03

luzr wrote on Mon, 12 July 2010 05:48

Sc0rch wrote on Sun, 11 July 2010 17:50

Hello, everyone!

Is there any example for this topic? In my program, when I try to use the Socket in threads, Socket is always closed. One variable: in main thread it's open, in other threads - closed. Why so?

Thank you,
Anton.


Hey, it is still the same story (as with SQL).

As soon as you have multiple threads and shared object, you HAVE TO "serialize" the access to the object using the mutex, so that only single thread "runs" the object at any given time. I mean, only single thread at any given time can read/write/execute members of object. This is what mutexes are for.

Rules are more fine-grained, but in practice this pretty much sums it.

Note: There ARE some objects where this does not hold, where you can call methods without mutex locking. Most of them are associated with multithreading, e.g. Mutex class itself... Smile


Yes, I know about Mutex from last thread. I'm using it for socket. Problem is: when I open static Socket in main loop (console app), and try to read it from thread, I'm getting ASSERT(IsOpen ... ). IsOpen for this Socket returns different results: in main thread - true, in other thread - false. I'm comfused about this, sorry if the reasons are stupid.

Sorry for my English,
Anton


Is not it possible that the thread gets to read it first?

If that seems OK, a little testcase would help...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SSL patch
Next Topic: Stop Download
Goto Forum:
  


Current Time: Fri May 10 09:46:05 CEST 2024

Total time taken to generate the page: 0.01878 seconds