Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Multi-Threading in C++?

Author
Message
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 5th Mar 2004 16:50
I'm making a socket plugin (look in the WIP section) and I need to make a function run without pausing the DBP program. It would be horrible if when you listend to a port, the game would halt untill someone connected to it! So, how do I make the socket listen to a port without stopping everything? I used the speach plugin and noticed the voice could continue speaking without stopping everything. How is that done?

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 5th Mar 2004 17:28
If your thinking about the socket plug-in, have a word with the author.

Quote: "I used the speach plugin "

My speech plugin??


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 5th Mar 2004 17:43
what do you mean? did someone already make a socket plugin that I don't know about? I AM the author!
And yes, your speach plugin. Is there any other?

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 5th Mar 2004 18:14 Edited at: 5th Mar 2004 18:15
Ah - you are the author of the socket plug-in... In which case there is no point in e-mail yourself then...

As for your problem, the best way would be to return the value of a memory address, which you would update continually in the plug-in using interrupts (or IanM's favourite - a thread). The DBPro program would then act on this value.

Quote: "And yes, your speech plugin. Is there any other"

There may or may not be...


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 6th Mar 2004 06:51
so, how do I do multi-threading? I've looked in books and there isn't any clue about this.

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Mar 2004 11:27
Have a word with IanM - I've never used them...


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Mar 2004 13:46
Threading for sockets? I know that a lot of Windows programmers swear by them, but us Unix programmers laugh at their lack of imagination ... Ha ha ha

Seriously though, there is really no need to use threading for a socket DLL. I've been using sockets for a few years without ever having to resort to using a thread. In Windows, there is actually *less* need to do so, thanks to the MS system of taking something standard and 'tweaking' it.

Anyway, the difficulty with threading *isn't* threading itself - that's quite easy. The problem is the coordination and sharing of resources between your threads using mutexes and semaphores.

If you have the platform SDK, take a look at CreateThread, CreateMutex, CreateSemaphore and all associated functions. You'll find examples there.

@TCA,
How do you do your interrupts then?

*** Soon to be released - A Network Plug-in ***

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6, .NET and soon for Dev-C++ http://www.matrix1.demon.co.uk
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 6th Mar 2004 17:34
Well, if you don't thread, then how do you get the game to continue
running while waiting for a connection?
I don't have much experience with sockets in C++, so I'm finding
some of this stuff quite confusing.

OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Mar 2004 18:17 Edited at: 6th Mar 2004 18:21
Your other alternative is to use interrupts.

My interrupts use SetTimer - I dont create a new thread for that.


The place for all great plug-ins.
XP3000+,1Gb RAM,FX5600,1Mb ADSL,Router,.Net 2003 Pro & me
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Mar 2004 20:07
@TKF15H,

Two ways ...
1 - Use a non-blocking socket - accept() will fail if there is no connection pending
2 - Poll the socket - it will be signalled as readable if there is a connection pending

You might want to buy a book or two on the subject of sockets - there is a lot to know.

I have 'UNIX Network Programming, Volume 1', written by W Richard Stevens. I've had it for a few years and it really is the best. It's not windows-specific, but it's an easy conversion to make

*** Soon to be released - A Network Plug-in ***

For free Plug-ins, source and the DBPro Interface library for Visual C++ 6, .NET and soon for Dev-C++ http://www.matrix1.demon.co.uk
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 7th Mar 2004 21:09
ok, thanks, IanM. I'll check if I can find a good book around here.
Since I'm in Brazil, it's very hard to find something in english. They
often have translations to portuguese which are often unreadable, and I
really don't like reading anything in portuguese any way.

Login to post a reply

Server time is: 2024-11-24 21:31:39
Your offset time is: 2024-11-24 21:31:39