Re: Threads !!!



Anil wrote:

I had no problems with gtk, when i am using them within a thread , by enclosing them within gdk_threads_enter and gdk_threads_leave.

But when i am using the gdk drawing functions like gdk_draw_line, gdk_draw_pixmap ...., i am gettting sync errors. How can i overcome this ?



How about having a single "worker" thread that does all the updating, and
all the other threads in your program sent it requests with the instructions
about what needs to be done and the data to do it? Possible implementation:

- have a queue (call it ui_event_queue) protected by a mutex
  (ui_event_mutex)
- the worker thread locks the queue, pulls off the first entry, unlocks the
  queue and processes the entry.
- the other threads lock the queue, add their request to the end then unlock
  the queue

That way you only ever have a single thread changing the ui.

Chris
--
=[ http://www.starforge.co.uk/ ]===[ Explorer2260 Lead Designer and Coder. ]
=[ Public key: ]===================[ http://www.starforge.co.uk/pubkey.txt ]
=[ Quod nesciunt eos interficiet. ]




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