Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 07:04

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ Threading

Discussion on C++ Threading within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Cyperghost's Avatar
 
elite*gold: 0
The Black Market: 379/0/0
Join Date: Jan 2013
Posts: 11,449
Received Thanks: 210
C++ Threading

Ich habe da mal eine frage zu Threading in C++

Wie kann ich eine Thread Array starten?
ich weiß das ich in C# es z.B. so machen kann


Code:
Thread[] myThread;

myThread= new myThread[Convert.ToInt32(1)];
            for (int i = 0; i <= Convert.ToInt32(1) - 1; i++)
            {
                myThread[i] = new Thread(new myThread(funktion));
                myThread[i].Start();
            }
Danke schon mal
Cyperghost is offline  
Old 02/28/2013, 18:23   #2
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Unter boost gibts ne thread_group (oder so ähnlich) Klasse. Via Bordmitteln von C++(11) mal hier eine Möglichkeit:
Code:
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include <utility>
#include <mutex>

const int THREAD_COUNT = 8;
std::mutex MUTEX;

void func()
{
	std::lock_guard<std::mutex> lg(MUTEX);
	std::cout << "called from thread " << std::this_thread::get_id() << std::endl;
}

int main()
{
	std::vector<std::thread> vec;
	for(int i = 0; i < THREAD_COUNT; ++i)
	{
		std::thread t(&func);
		vec.push_back(std::move(t));
	}

	for(auto& t : vec)
	{
		t.join();
	}
}
Schlüsselbein is offline  
Thanks
2 Users
Old 02/28/2013, 20:53   #3

 
Delinquenz's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,160
Received Thanks: 232
Kann die Antwort meines Vorposters nur unterstreichen.. benutze immer Threads in Verbindung mit Vektoren - bisher erfolgreich.
Delinquenz is offline  
Thanks
1 User
Old 03/01/2013, 07:27   #4
 
Cyperghost's Avatar
 
elite*gold: 0
The Black Market: 379/0/0
Join Date: Jan 2013
Posts: 11,449
Received Thanks: 210
ah Danke euch
Cyperghost is offline  
Reply


Similar Threads Similar Threads
Threading
02/22/2013 - Nostale - 3 Replies
Hi!I have a question for what i need multithreading i developing game server.Soo i know that i need this for connection.
C++ Threading
03/24/2012 - CO2 Programming - 13 Replies
Anybody got some good threading tutorials in c++? #Edit Using boost would be fine?
Threading
11/18/2011 - CO2 Private Server - 10 Replies
What should I do? A thread for every map that's used by players, a global thread for all players or a single thread for every player.
[C++] Problem with threading
05/17/2009 - CO2 Programming - 2 Replies
Actually the problem is more like with passing a function as pointer to the CreateThread or _beginthreadex, BOOL Connect() { if(m_Enabled != TRUE) return FALSE; sockaddr_in addr; addr.sin_family = AF_INET;
[C#] Cross-Threading ?
10/14/2008 - .NET Languages - 7 Replies
Hello, Is there a flag or whatever that lets me use crossthreading freely? Without the help of a Workerthread. Whenever I try to change a variable it doesn't let me because Crossthreading isn't safe (eg. accessing the variables from other threads), but It's also hard to find a solution for this. I'm starting another thread that contains a function to download the source code of another page and process the wanted information into variables, however I cannot do that with a thread. The only...



All times are GMT +1. The time now is 07:04.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.