I wrote a threaded multiplayer networking, but my threads stopped being created when client connected so i wrote test which reproduces the problem, but with just creating threads code.
#include <iostream>
#include <SFML/System.hpp>
void thread_one(int* counter) {
for(int i = 5; i < 100; i++) {
sf::Sleep(500);
}
}
void thread_two(int* counter) {
for(int i = 5; i < 100; i++) {
sf::Sleep(500);
}
}
int main() {
int counter = 2;
while(true) {
sf::Sleep(1000);
sf::Thread * threadOne = new sf::Thread(&thread_one, &counter);
sf::Thread * threadTwo = new sf::Thread(&thread_two, &counter);
threadOne->Launch();
threadTwo->Launch();
std::cout << "Two threads launched!" << counter << std::endl;
counter += 2;
}
}
This code starts failing to create threads after few hundred threads and i will be needing like 4000 threads.
I'm running linux so it creates pthreads and gives me the error message from the linux version of Launch() function. Oh yeah and i'm using SFML 2.
Care to help?