Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #138710
| From | rbowman <bowman@montana.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Multithreading |
| Date | 2018-12-16 21:00 -0700 |
| Message-ID | <g7ol8vFu0u7U1@mid.individual.net> (permalink) |
| References | <5c16c53f.660858109@news.xmission.com> |
On 12/16/2018 02:48 PM, Scott wrote: > What I'd like to ask for are recommendations on resources for learning > about the principles and pitfalls of threaded programming, in a > general way, not tied to any specific implementation. I'm muddling my > way through this exercise, but I have this feeling that I'm taking a > Sunday stroll through a live minefield and just haven't managed to > walk into anything really interesting yet. Oh, there are definitely mines... https://www.thegeekstuff.com/2012/05/c-mutex-examples/?refcom That's one of the first pages I hit. There may be better examples but it does discuss one of the major minefields. Logically threads can simplify the code. For example, you can thread off something to read from a socket. It can block, no big deal, so you don't have to go to a non-blocking socket, select statements, and all that good stuff to keep the ball rolling. Where it gets tricky is when it has read data from a socket and now has to pass it to another thread. Lets say you want to insert it into a linked list to be consumed by the other thread. The other thread is blissfully unaware of the socket reader and is happily processing the list and doing something with the data. Somebody has to say 'hey, I'm modifying the list' with the other thread waiting for its turn. You need to watch out for deadlocks or both threads wind up politely waiting on each other. It can bite you at odd moments. I'm old school and like to salt the code with fprintf's to a log file while I developing so I can construct a narrative of what's supposed to be happening. Even that needs to be set up with a mutex so the threads aren't simultaneously trying to write to the same log. It's really not that complicated and you just need to think about where each thread will interact with a common object and keep them playing nicely together.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multithreading nobody@example.org (Scott) - 2018-12-16 21:48 +0000
Re: Multithreading Joey Pabalinas <joeypabalinas@gmail.com> - 2018-12-16 17:11 -1000
Re: Multithreading rbowman <bowman@montana.com> - 2018-12-16 21:00 -0700
Re: Multithreading Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-12-17 22:19 +0000
Re: Multithreading Joey Pabalinas <joeypabalinas@gmail.com> - 2018-12-17 12:45 -1000
Re: Multithreading nobody@example.org (Scott) - 2018-12-19 19:48 +0000
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:58 -0800
Re: Multithreading Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-12-19 23:17 +0000
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:31 -0800
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:34 -0800
Re: Multithreading nobody@example.org (Scott) - 2018-12-22 10:43 +0000
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-22 03:41 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-22 03:46 -0800
Re: Multithreading Thiago Adams <thiago.adams@gmail.com> - 2018-12-22 07:14 -0800
Re: Multithreading rbowman <bowman@montana.com> - 2018-12-22 11:41 -0700
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-22 16:09 -0800
Re: Multithreading scott@slp53.sl.home (Scott Lurndal) - 2018-12-22 19:52 +0000
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-22 16:10 -0800
Re: Multithreading nobody@example.org (Scott) - 2018-12-23 23:11 +0000
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-23 15:24 -0800
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-23 15:25 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-24 02:05 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-24 02:08 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-18 07:18 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-18 07:51 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 09:24 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 09:55 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:02 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:16 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 11:25 -0800
Re: Multithreading "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-19 15:37 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-19 16:03 -0800
Re: Multithreading fir <profesor.fir@gmail.com> - 2018-12-20 08:02 -0800
csiph-web