Programacion en hilos (threads)

Moderador: yalmar

Foro cerrado salvo peticion.

Programacion en hilos (threads)

Notapor pcREIDe » Mar Jun 27, 2006 10:02 am

Hola, quiero aprender a trabajar con hilos en c++ pero no encuentro bibliografia para esto, si alguien pudiera ayudarme con esto de cualquier forma posible se los agradeceria mucho, ya sea con tutoriales o alguna explicacion.

S@lu2s.
pcREIDe
Novato
Novato
 
Mensajes: 11
Registrado: Mar Jun 27, 2006 9:11 am


Posible Solucion

Notapor enoc » Sab Jul 08, 2006 12:39 am

Este ejmplo esta en las ayuda de Borland Buscar por threads

Espero que te sirva
saludos
Nicolas


Example: This service beeps every 500 milliseconds from within the standard thread. It handles pausing, continuing, and stopping of the thread when the service is told to pause, continue, or stop.

1 Choose File|New and select Service Application from the New Items dialog. You will see a window appear named Service1.
2 In you unit’s header file, declare a new descendant of TThread named TSparkyThread. This is the thread that does the work for your service. The declaration should appear as follows:

class TSparkyThread : public TThread

{
private:
protected:
void __fastcall Execute();
public:
__fastcall TSparkyThread(bool CreateSuspended);
};

3 Next, in the .cpp file for your unit, create a global variable for a TSparkyThread instance:

TSparkyThread *SparkyThread;

4 Add the following code to the .cpp file for the TSparkyThread constructor:

__fastcall TSparkyThread::TSparkyThread(bool CreateSuspended)

: TThread(CreateSuspended)
{
}

5 Add the following code to the .cpp file for the TSparkyThread Execute method (the thread function):

void __fastcall TSparkyThread::Execute()

{
while (!Terminated)
{
Beep();
Sleep(500);
}
}

6 Select the Service window (Service1), and double-click the OnStart event in the Object Inspector. Add the following OnStart event handler:

void __fastcall TService1::Service1Start(TService *Sender, bool &Started)

{
SparkyThread = new TSparkyThread(false);
Started = true;
}

7 Double-click the OnContinue event in the Object Inspector. Add the following OnContinue event handler:

void __fastcall TService1::Service1Continue(TService *Sender, bool &Continued)

{
SparkyThread->Resume();
Continued = true;
}

8 Double-click the OnPause event in the Object Inspector. Add the following OnPause event handler:

void __fastcall TService1::Service1Pause(TService *Sender, bool &Paused)

{
SparkyThread->Suspend();
Paused = true;
}

9 Finally, double-click the OnStop event in the Object Inspector and add the following OnStop event handler:

void __fastcall TService1::Service1Stop(TService *Sender, bool &Stopped)

{
SparkyThread->Terminate();
Stopped = true;
}

When developing server applications, choosing to spawn a new thread depends on the nature of the service being provided, the anticipated number of connections, and the expected number of processors on the computer running the service.
Ing Edwin Nicolas Orozco
enoc
Novato
Novato
 
Mensajes: 3
Registrado: Sab Jun 17, 2006 6:29 pm
Ubicación: Bogota



    

Volver a C++ Builder

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados