Need multithread sleep

Mar 4, 2017 at 5:32pm
closed account (yb54LyTq)
deleted
Last edited on Mar 5, 2017 at 4:53am
Mar 4, 2017 at 6:08pm
While you wait for an answer clever than mine, what about taking a glance to this thread with the wonderful code by JLBorges?
http://www.cplusplus.com/forum/beginner/170097/
Mar 4, 2017 at 8:24pm
closed account (yb54LyTq)
deleted
Last edited on Mar 5, 2017 at 4:53am
Mar 4, 2017 at 8:38pm
I'm completely new to C++ so bear with me. I have some code that someone else wrote
I'm a complete newbie to programming.

So... are you new to programming and you decided to begin by C++ with an undocumented multi-threading code written by somebody else? Is that right?
Wow, let me say I admire you. You really a brave guy. My best wishes.
Hope somebody else will come and help you, I'm a very beginner with multi-threading and I won't be of any help.
Mar 5, 2017 at 1:28am
@OP
Enoizat wrote:
So... are you new to programming and you decided to begin by C++ with an undocumented multi-threading code written by somebody else? Is that right?
Wow, let me say I admire you. You really a brave guy. My best wishes.
Hope somebody else will come and help you, I'm a very beginner with multi-threading and I won't be of any help.

I could say the same thing. You don't show any efforts to begin with, and we also can't help someone who doesn't understand anything about C++ at all. Solutions will not help you learn and will likely encourage your laziness.
Last edited on Mar 5, 2017 at 1:29am
Mar 5, 2017 at 1:51am
ok, why does sleep hang the thread? It should put the thread to sleep for 30 then wake up right where it left off. You can put a busy-wait in there, but that kills your performance... burns a cpu for nothing.
Mar 5, 2017 at 4:26am
closed account (yb54LyTq)
deleted
Last edited on Mar 5, 2017 at 4:53am
Mar 5, 2017 at 4:31am
If I simply do Sleep(30) it will freeze the app for 30 seconds and the window will not respond.

Sleep(30) only freezes the thread for 30 milliseconds.

And how to create a separate thread so that you can freely use Sleep() without affecting your main window :
http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c

Edit : You need to keep your thread alive, not delete it.

nelwyn wrote:
I'm completely new to C++ so bear with me. I have some code written by someone else and I'm looking for a way to make it display something, then wait 30 seconds and display something different. Basically it's a 2 minute countdown with 30 second interval to say something.

The SystemBroadcast is what prints the message so I want a way to do this 4 times with a 30 second wait in between. The message will be different each time. I've only been able to do this with Sleep but obviously that's a bad thing as it will hang the thread.

This is the portion shown that I want to modify. If I need to include the whole thing, just let me know. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 CPhatServer::~CPhatServer()
{
	if (g_pNetwork)
	{
		SystemBroadcast("2 Minutes");
		g_pNetwork->Think();
		SafeDelete(g_pNetwork);
	}
	SafeDelete(g_pWorld);
	SafeDelete(g_pGameDatabase);
	SafeDelete(g_pDB2);
	SafeDelete(g_pDB);
	SafeDelete(g_pGameRules);
	SafeDelete(g_pCell);
	SafeDelete(g_pPortal);

	for (int i = 0; i < m_socketCount; i++)
	{
		if (m_sockets[i] != INVALID_SOCKET)
		{
			closesocket(m_sockets[i]);
			m_sockets[i] = INVALID_SOCKET;
		}
	}
}
Last edited on Mar 5, 2017 at 4:58am
Mar 5, 2017 at 5:06am
closed account (yb54LyTq)
There's nothing useful in this thread and I'm getting nothing but a hard time here so I'll look elsewhere for help.
Topic archived. No new replies allowed.