![]() |
Модераторы: Daevaorn |
![]() ![]() ![]() |
|
Люда |
|
|||
![]() Шустрый ![]() Профиль Группа: Участник Сообщений: 71 Регистрация: 24.4.2002 Репутация: нет Всего: нет |
Есть такая проблемка -программа доходит до конца, но сама консоль не убиратся, т.е.
void main() { .................................. printf("\n finish"); Sleep(5000L); return; } на консоле появляется надпись "finish" и дальше ничего не поисходит, в процессах этой задачи нет, по кресту не закрывается, короче избавиться от нее невозможно, причем происходит это не всегда, а совершенно случайным образом, может кто сталкивался с чем-то подомным ![]() В проге используется многопоточность |
|||
|
||||
bel_nikita |
|
|||
![]() Эксперт ![]() ![]() ![]() ![]() Профиль Группа: Эксперт Сообщений: 2304 Регистрация: 12.10.2003 Где: Поезд №21/22 ( ст . Прага ) Репутация: 21 Всего: 47 |
А потоки, точно, все убиваешь? |
|||
|
||||
OlegsDP |
|
|||
Новичок Профиль Группа: Участник Сообщений: 37 Регистрация: 25.2.2004 Репутация: нет Всего: 1 |
Попробуйте заканчивать программу вот этой функцией:
The ExitProcess function ends a process and all its threads. VOID ExitProcess( UINT uExitCode // exit code for all threads ); Parameters uExitCode Specifies the exit code for the process, and for all threads that are terminated as a result of this call. Use the GetExitCodeProcess function to retrieve the process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value. Return Values This function does not return a value. Remarks ExitProcess is the preferred method of ending a process. This function provides a clean process shutdown. This includes calling the entry-point function of all attached dynamic-link libraries (DLLs) with a value indicating that the process is detaching from the DLL. If a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination. After all attached DLLs have executed any process termination value, this function terminates the current process. Terminating a process causes the following: 1. All of the object handles opened by the process are closed. 2. All of the threads in the process terminate their execution. 3. The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate. 4. The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate. 5. The termination status of the process changes from STILL_ACTIVE to the exit value of the process. Terminating a process does not cause child processes to be terminated. Terminating a process does not necessarily remove the process object from the operating system. A process object is deleted when the last handle to the process is closed. The ExitProcess, ExitThread, CreateThread, CreateRemoteThread functions, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. This means the following restrictions hold: · During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process. · Only one thread in a process can be in a DLL initialization or detach routine at a time. · ExitProcess does not return until no threads are in their DLL initialization or detach routines. |
|||
|
||||
OlegsDP |
|
|||
Новичок Профиль Группа: Участник Сообщений: 37 Регистрация: 25.2.2004 Репутация: нет Всего: 1 |
На самом деле, если у Вас в программе несколько тредов, то корректно было бы подождать завершения всех тредов, и лишь затем завершать апликацию. Подождать можно функцией WaitForSingleObject или WaitForMultipleObjects.
|
|||
|
||||
bel_nikita |
|
|||
![]() Эксперт ![]() ![]() ![]() ![]() Профиль Группа: Эксперт Сообщений: 2304 Регистрация: 12.10.2003 Где: Поезд №21/22 ( ст . Прага ) Репутация: 21 Всего: 47 |
Сорри, бес попутал
![]() Это сообщение отредактировал(а) bel_nikita - 1.3.2004, 16:54 |
|||
|
||||
Люда |
|
|||
![]() Шустрый ![]() Профиль Группа: Участник Сообщений: 71 Регистрация: 24.4.2002 Репутация: нет Всего: нет |
Я заканчиваю программу только после закрытия всех потоков, попробуювоспользоваться ф-цией ExitProcess, спасибо |
|||
|
||||
![]() ![]() ![]() |
Правила форума "С++:Общие вопросы" | |
|
Добро пожаловать!
Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Earnest Daevaorn |
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
0 Пользователей: | |
« Предыдущая тема | C/C++: Общие вопросы | Следующая тема » |
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |