[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] non blocking sleep

Carl Karsten <carl@xxxxxxxxxxxxxxxx> writes:

> Oh wait, that fires that off a thread and can return to paho's event loop,
> right?
>
> I have no idea what happens in the timer thread, but I trust this will all
> just work as needed.  I hope.

Generally, the standard approach is to have a single event loop in a program.
Otherwise, you need locking between them, and if you aren't really clear
on how locking is done and why, you'll have trouble.

> I was thinking i needed my own event loop, which would need to play nice
> with paho, which I still only 1/2 understand how it can run in it's own
> thread if needed.

(Sorry, I am still on the "going to learn py-paho any day now" plan.)

> I think this is the first time I have really had to pay attention to
> threads.

Beware that threads are 10x harder than you think they are, unless
you're a cranky old-school programmer who warns people about threads.
Basically, you have to get the locking right by design and code review,
because it's basically not debuggable since unsound code will usually
work.  Although there is very recently "TSan" which probably makes
things much better.