Re: Pthread Help

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

 



Hi!

On 03:18 Tue 12 Aug     , Mohammed Mustaq wrote:
> Hi .
> 
> ???I am not sured whether this is correct mailing List to post this message ? Any help would appreciate .? 
> 
> ????I have more more then 30 threads in a single process . I want to have sanity control for all threads i.e suppose either some thread has been stopped or some have been locked ( may be dead lock ) .
>  ???This could be done by having message Qs in all threads and broadcasting messages by any single thread?to?all and getting some reply .Except this ,
> 
> ??Is there any mechanism that thread manager can watch all threads ? or Any Other ?
> 
> ??Am i missing something ?

I think that is a very bad idea. Threading synchronisation is *hard* and
deadlocks are just a part. If you do not know when threads stop, a "thread
manager" will not help you. You can try these things:

- Avoid using threads: many io operations can be done in a non-blocking way and
  multiplexed with e.g. epoll. Timers can be also handled by this thread. This
  is often faster than creating multiple threads in is quite often done (e.g.
  lighttpd)

- Do not use locked shared memory, but message passing and/or transaction
  based "shared memory" (e.g. database, software emulated transactional memory)
  to do the synchronisation. Be aware of what happens when message passing
  queues get big. If they grow with no limit, your application might eat easily
  "eat" all available memory. If there is a limit, you might run into a
  deadlock, when 2 threads wait until they can pass a message to the other one.

- Give the thread synchronisation the attention it deserves. It is not
  something you can can do on trial-and-error, because in many cases, you will
  not see the error. It will just appear on some machines depending on number
  an type of cpu, the process scheduler, amount of memory (swapping), other
  programs running in the background. This is why many people who know what
  they are doing *hate* threading and often try to avoid it. Actually it
  introduces a completly now type of bugs. Trying to improve performance
  without, any *measurement* can be called "premature optimisation" and this is
  a rather bad idea.
	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux