Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Threadlimit?  (Read 3860 times)

0 Members and 1 Guest are viewing this topic.

affiliated

  • Newbie
  • *
  • Posts: 2
    • View Profile
Threadlimit?
« on: September 28, 2008, 04:49:31 pm »
Hi,

Im trying to write an application that uses threads to handel multible network connections. For each Client there is a Client,Send,Recieve-Thread. After about 200 Clients, this would be 600 Threads, i got the message "Failed to create Thread".

Is it my Operating System or some SFML that reaches some limit? Im trying this on an Debian Etch. I tried to find my system limit of processes but failed.

Thanks for your time.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Threadlimit?
« Reply #1 on: September 28, 2008, 10:18:39 pm »
SFML doesn't add any limitation on top of the OS ones.

By the way, 600 threads sounds a little bit overkill... The system spends more time switching between threads than executing them.
Have you ever thought about asynchronous sockets or selectors ?
Laurent Gomila - SFML developer

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Threadlimit?
« Reply #2 on: October 01, 2008, 11:46:01 pm »
The absolute maximum for threads is (on normal workstations) given by Hardware, and approximately 8192 (but a little less) because of the limited amount of LDT entries in the GDT (I dont know if this value is increased e.g. for 64-bit-CPUsor Multicore CPUs).
But I think most OS prevent you from creating more than approx 800 threads/processes because of performance reasons. Not only that they need much time to switch, but they also use a big amount of memory, since they have own stacks and so on...

chriss

  • Newbie
  • *
  • Posts: 7
    • View Profile
Threadlimit?
« Reply #3 on: July 02, 2009, 07:47:14 pm »
I found this topic with google.

I have nearly the same problem as describet at top.
After a while i become the message "Failed to create thread".

I'm writing a server application that has to run 24 hours the whole week.

I'm using less than 10 threads for looping checks, many threads are used by the network library raknet.
So far so good.


Every time a user initiates an action a thread is createt and executet. Those threads have a regulary lifetime of max. one second.

So my main questin on this: Do those threads destroy themself after reaching the end of the execution function or do they stay alive?

Because i'm creating tones of threads i'm wondering if i hvae to reuse the old ones (since this topic).


I hope anyone understands my problem and can tell me if i have to reuse old threads or another issue in my application.


Thanks,   Chriss

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32451
    • View Profile
    • SFML's website
    • Email
Threadlimit?
« Reply #4 on: July 02, 2009, 08:36:09 pm »
The destructor of sf::Thread will properly wait for it to terminate. So, if the threaded function ends properly, the thread's resources are always freed as expected.

You should check the OS' current error after you get a "Failed to create thread" (GetLastError on Windows).
Laurent Gomila - SFML developer

chriss

  • Newbie
  • *
  • Posts: 7
    • View Profile
Threadlimit?
« Reply #5 on: July 04, 2009, 04:28:50 pm »
Thanks for that info.