• Log in or sign up for an account here: https://www.sythe.org/login

Multi-Threading?

Esuom

Guru

Banned
Joined
May 3, 2007
Sythe Gold
0
Messages
1,731
Location
EST Time Zone.
Can anyone give me a little bit of information on multi threading in C++? Is there any easy-ish way to do it?
 
What are you looking to accomplish?

Threading is complicated in just about every language but can (usually) be simply avoided...
 
Threading is complicated in just about every language but can (usually) be simply avoided...
It's not too complicated in Java... I'd even recommend learning it first there.

You're probably right though cp in that his needs wouldn't require threading. I think he just wants to learn it anyway.
 
Member of the Month Winner
Sythe's 10th Anniversary
What are you looking to accomplish?

Threading is complicated in just about every language but can (usually) be simply avoided...
Threading in .Net is actually fairly easy as well, the only problem I have is Mutex (MUTual EXclusion), and interacting between the main thread and so on.

But yeah, threading will be hard in C++ to master, so be prepared to spend a long time learning it.
 
Yea, I read a few more guides that I found on google, it isn't really worth my time.


My problem is, I am trying to grab the source of a page and then find one string in it, the function I am using is just too slow.
 
My problem is, I am trying to grab the source of a page and then find one string in it, the function I am using is just too slow.
Post what you're using? I'm pretty sure I've done that or something very similar before it was wasn't that badly performing.
 
Code:
string GetSource(char m_strURL[])
{
	if ( m_strURL == "" )
	{
		return "";
    }

	HINTERNET hINet, hFile;
	hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );

	if ( !hINet )
	{
		return "";
	}

	hFile = InternetOpenUrl( hINet, m_strURL, NULL, 0, 0, 0 ) ;
    string m_strContents;

	if ( hFile )
	{
		CHAR buffer[1024];
		DWORD dwRead;
		while ( InternetReadFile( hFile, buffer, 1023, &dwRead ) )\
		{
			if ( dwRead == 0 )
				break;
			buffer[dwRead] = 0;
			m_strContents += buffer;
		}
		InternetCloseHandle( hFile );
	}
	InternetCloseHandle( hINet );  
    return m_strContents;    
}


A friend wrote it for me, I don't know if there is a better method?
 
That's pretty much functionally equivalent to the code I'd been using. I thought you were saying that searching for the string was slow but I now realize you mean that getting the source is slow and I had that same issue. It's late right now but I'll see if I can write up a better get source tomorrow or the next day using socket programming.

EDIT: What compiler do you use and what Operating System are you running?
 
That's pretty much functionally equivalent to the code I'd been using. I thought you were saying that searching for the string was slow but I now realize you mean that getting the source is slow and I had that same issue. It's late right now but I'll see if I can write up a better get source tomorrow or the next day using socket programming.

EDIT: What compiler do you use and what Operating System are you running?

Windows Vista and Dev-C++. I will be moving on to VC++ soon enough, but my class requires me to use Dev.
 
Member of the Month Winner
Sythe's 10th Anniversary
Windows Vista and Dev-C++. I will be moving on to VC++ soon enough, but my class requires me to use Dev.
This is sort of off-topic, but may I suggest Code::Blocks? It is a much more up-to-date IDE with a lot more functionality. Dev-C++ is so featureless it's not funny IMHO.

I'll take a look at your code later as well, although I'm not familiar with Windows functions. I tend to use 3rd-party libraries so I can port things.
 
This is sort of off-topic, but may I suggest Code::Blocks? It is a much more up-to-date IDE with a lot more functionality. Dev-C++ is so featureless it's not funny IMHO.

I'll take a look at your code later as well, although I'm not familiar with Windows functions. I tend to use 3rd-party libraries so I can port things.

I know this is an old ass post, and swan is gone, but I figured he may see this.


My teacher for the class was an old school nazi. She required me to use Dev-C++ and because Namespace std wasn't in our books, we couldn't use it. I failed the exam and went from a 99% in the class to an 80% because I used namespace std on my exam.
 
Old thread is old. Please don't grave dig.

EDIT: Reopened due to a request.
 
Runescape Gamblingrunescape gambling
Back
Top