Re: Concurrent processes



>Is there a way to let me change parameters ? Maybe lookup signals or
>somenthing like that ? I've heard something about threads but I don't
>know what it is.... I'm really a newbie so if someone could give me some
>very detailled way to do this, it would be very nice.

nobody is going to give you a detailed enough account without simply
pointing you at source code. 

a thread is bit like a process, except that instead of being an
entirely separate program with its own protected virtual memory, it
runs with complete access to the memory of the thread in which it was
started. when you start a new process, you can't share data without
specific arrangements to do so. when you start a new thread, all data
is shared between all the threads in the process. the different
threads all run "concurrently", where "concurrently" means
time-sharing however many processors your system has with any other
threads in any other processes that are ready to run.

you can start by reading up on the pthreads library. then, from
handler for the adjustment->changed signal, you can do this:

	void *my_computationally_intensive_thread (void *arg)
	{
		... do the stuff you want here ...
        }

	gint
	adjustment_changed_handler (GtkWidget *widget)
	{
            pthread_t thread_id;

	    pthread_create (&thread_id, NULL,
			    my_computationally_intensive_thread,
			    0);
            pthread_detach (thread_id);

            return TRUE;
        }			    

Thats just the bare bones. You'll no doubt need some mutexes to
prevent various bad things from happening, and you should almost
certainly make no calls to GTK or GDK from the separate thread. If you
plan to do that, there's a bit more work you need to do.

I happen to like a book called "Programming With Threads" by Kleiman
et al. but there are many others on the topic floating around.

--p




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