Модераторы: Daevaorn
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Создание потоков на Builder 6 
V
    Опции темы
Sergio
  Дата 28.1.2007, 19:39 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 843
Регистрация: 28.7.2006
Где: Solar System-> Earth

Репутация: 0
Всего: 1



Здраствуйте. Читал книгу Рихтера по потокам и вот столкнулся с ними на практике. Что-то не очень выходит smile Нужно запихнуть в поток вот этот вечный цикл и запустить поток в мейне:
Код

  while(1)
   {
    int x = x++;
   }


Вот как я делаю:
Код

 DWORD WINAPI MyThread(LPVOID lpParam)
 {
  while(1)
   {
    int x = x++;
   }
  return 0;
 }



Код

int main(int argc, char* argv[])
{
  DWORD res;
 CreateThread(NULL,0,ClientThread, ???, 0, res);
}

Я не понял что в парамете должно быть там где знаки вопроса smile 
Зарание спасибо.


Это сообщение отредактировал(а) Sergio - 28.1.2007, 19:49
PM MAIL ICQ   Вверх
Romikgy
Дата 28.1.2007, 19:55 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Любитель-программер
****


Профиль
Группа: Участник Клуба
Сообщений: 7326
Регистрация: 11.5.2005
Где: Porto Franco Odes sa

Репутация: 8
Всего: 146



CreateThread(NULL,0,ClientThread, NULL , 0, res);
Цитата

The CreateThread function creates a thread to execute within the address space of the calling process. 

HANDLE CreateThread(

    LPSECURITY_ATTRIBUTES lpThreadAttributes,    // pointer to thread security attributes  
    DWORD dwStackSize,    // initial thread stack size, in bytes 
    LPTHREAD_START_ROUTINE lpStartAddress,    // pointer to thread function 
    LPVOID lpParameter,    // argument for new thread 
    DWORD dwCreationFlags,    // creation flags 
    LPDWORD lpThreadId  // pointer to returned thread identifier 
   );    
 

Parameters

lpThreadAttributes

Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited. 

Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor. 
Windows 95: The lpSecurityDescriptor member of the structure is ignored.

dwStackSize

Specifies the size, in bytes, of the stack for the new thread. If 0 is specified, the stack size defaults to the same size as that of the primary thread of the process. The stack is allocated automatically in the memory space of the process and it is freed when the thread terminates. Note that the stack size grows, if necessary. 
CreateThread tries to commit the number of bytes specified by dwStackSize, and fails if the size exceeds available memory.

lpStartAddress

The starting address of the new thread. This is typically the address of a function declared with the WINAPI calling convention that accepts a single 32-bit pointer as an argument and returns a 32-bit exit code. Its prototype is:

DWORD WINAPI ThreadFunc( LPVOID );

lpParameter

Specifies a single 32-bit parameter value passed to the thread. 

dwCreationFlags

Specifies additional flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state, and will not run until the ResumeThread function is called. If this value is zero, the thread runs immediately after creation. At this time, no other values are supported.

lpThreadId

Points to a 32-bit variable that receives the thread identifier. 

или юзай класс TThread

Это сообщение отредактировал(а) Romikgy - 28.1.2007, 19:56


--------------------
Владение русской орфографией это как владение кунг-фу — истинные мастера не применяют его без надобности. 
smile

PM   Вверх
Sergio
Дата 28.1.2007, 20:01 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 843
Регистрация: 28.7.2006
Где: Solar System-> Earth

Репутация: 0
Всего: 1



Спасибо.
PM MAIL ICQ   Вверх
nworm
Дата 28.1.2007, 20:01 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 502
Регистрация: 22.10.2005

Репутация: 1
Всего: 8



Это 
Код

LPVOID lpParam

который передаётся в функцию 
Код

 MyThread(LPVOID lpParam)


А, ещё, надо поправить
Код

CreateThread(NULL,0,MyThread, ???, 0, res);


Это сообщение отредактировал(а) nworm - 28.1.2007, 20:04
PM MAIL WWW   Вверх
Ustus
Дата 29.1.2007, 20:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 10
Регистрация: 19.1.2007

Репутация: нет
Всего: 2



Кстати, здесь есть одна проблема, как сказано в help'е:
Код

A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called. 

PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "С++:Общие вопросы"
Earnest Daevaorn

Добро пожаловать!

  • Черновик стандарта C++ (за октябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика(4.4мб).
  • Черновик стандарта C (за сентябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика (3.4мб).
  • Прежде чем задать вопрос, прочтите это и/или это!
  • Здесь хранится весь мировой запас ссылок на документы, связанные с C++ :)
  • Не брезгуйте пользоваться тегами [code=cpp][/code].
  • Пожалуйста, не просите написать за вас программы в этом разделе - для этого существует "Центр Помощи".
  • C++ FAQ

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Earnest Daevaorn

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0977 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.