Differences between al_run_detached_thread() and al_start_thread()
AMCerasoli

Hi guys...

I have a question about some threading functions, yes again... :-[

  1. What is the difference from al_run_detached_thread() and al_start_thread()? The unique and obvious difference that comes to mind is the fact that with the first function you have no control over such thread, instead with the second one you have the ability to make it stop when you want. However both of them allows you you use mutexs and conds, isn't it?.


  2. When I call al_create_thread() the windows task manager shows that my game creates a new thread, and when I call al_start_thread() it creates another one, but then it disappears. But when I call al_destroy_thread() it only destroys one, but if I call again al_create_thread() and al_create_thread() again, it only creates one thread, and when I destroy it, again it only destroys one, so it doesn't look too bad, ex:

threads : 15

al_create_thread()
threads : 16
`
al_start_thread()
Threads : 17
Threads : 16

al_destroy_thread()
Threads : 16

al_create_thread()
al_start_thread()

Threads : 17
Threads : 16

So, all this crap is to know if I'm doing something bad, or if it is a normal behavior. In case I'm not doing something wrong, it's obvious that in my case would be better to use al_run_detached_thread(), since I don't need to close the thread for the main thread manually, am I right?.

Elias

I don't think al_create_thread and al_destroy_thread do anything but allocate/free the memory. al_start_thread will start the thread and it ends when you return from it. Would that explain the numbers you are seeing?

Thomas Fjellstrom

As far as I can tell, al_create_thread actually spawns the thread, and it sits waiting for a condition variable fired by al_start_thread, then it launches into the user proc. I'm not entirely sure why the thread api is set up that way, but it is.

AMCerasoli

Well, probably it's the Task Manager not being precise, I thought it was a reliable tool. Here's a video showing the normal game.

video

And in this video some experiments that I can't understand.

video

PS: I'm not creating another threads besides this, in my game, so, I think it could be Allegro, or the Task Manager not being precise.

Arthur Kalliokoski

Have you tried Process Explorer?

AMCerasoli

Wow, good tool.

It's showing the same information than the Task Manager, though. The game always starts with 15 threads and if I let it alone some time (maybe 5 min) drops to 12 threads, when I call al_create_thread() it creates another thread, the Process Explorer shows its Start Address is "msvcrt.dll!_endthreadedx+0x29".

But I have just realized that such thread also disappear after some minutes, so there is no problem. Thanks for the tool Arthur.

Thanks to all.

Thread #609259. Printed from Allegro.cc