How to do multi-threading ?



Hi,

I need something like this :

1. An aplication with a START and STOP button.
2. The START should set a variable to TRUE (running = TRUE) and call a
function with an infinite loop like:

void infiniteLoop()
{
	while(running){
		/* do something */
	}
}

3. The STOP should set the variable FALSE so that to force the
infiniteLoop to finish.

I have try to set callbacks to START and STOP buttons, but the
infiniteLoop doesn't let other signals to be emitted. 

I have done something like this:

main()
{
....
  gtk_signal_connect (GTK_OBJECT (startButton), "clicked", 
		      GTK_SIGNAL_FUNC(startButton_clicked_event), NULL);
  gtk_signal_connect (GTK_OBJECT (stopButton), "clicked", 
		      GTK_SIGNAL_FUNC(stopButton_clicked_event), NULL);
....
}

void startButton_clicked_event (GtkWidget *widget, gpointer data)
{
  running = true;
  infiniteLoop();
}

void stopButton_clicked_event (GtkWidget *widget, gpointer data)
{
  running = false;
}

I have try to use <pthread.h> but I get sigsegs and I find no docs or
examples on how to use the threads in Linux.

Any ideea will be higly apreciated. 8-)

Please answer me.

TIA,

Ionutz



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]