in reply to Re: issue of concurrency: which module is better
in thread issue of concurrency: which module is better
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: issue of concurrency: which module is better
by roboticus (Chancellor) on Oct 08, 2010 at 11:55 UTC | |
As with many questions, "it depends". Without knowing more about the problem(s) you're solving, no-one can give you a good answer. To me, the question sounds something like:
Obviously, that would depend on *your* circumstances. If you were an outdoorsman who frequently camps in the mountains, the Explorer could be the best vehicle for you. If you just liked cruising country roads with the top down, the Miata would be far better. With your problems, if sharing memory was the most important criterion, I might investigate using a single task driving a set of state machines. Depending on what you're trying to do, this might give you the best performance with everything shared. If you share only a little bit of data--but very frequently--then I might use threads. On the other hand, if you less frequently share more complicated data, then I might advise the use of forking and share the data via a database, an IPC class, or some such. Without context, it's quite easy to give advice that you'll find to be wrong for your situation. ...roboticus Update: Oops! Minor edit: s/top down, would/top down, the Miata would/ | [reply] [d/l] |
by llancet (Friar) on Oct 09, 2010 at 05:33 UTC | |
Actually, quite complicated. I use concurrency in different situations: Firstly, in order to take advantage of multi processor (I have a 12-core workstation), I want to run multiple programs (actually, NCBI blast) at one time. Currently, I solve this by create several perl threads, and run one program in each thread. It works well. In another situation, I'm making a large ugly GUI program (uses Gtk2), and I want the GUI keep active while background work is running. However, there are some complexed data structure that need to be accessed by both the GUI and worker thread, so I really wants a "real" thread that shares everything by default, but not copying. | [reply] |
by BrowserUk (Patriarch) on Oct 09, 2010 at 08:51 UTC | |
In another situation, I'm making a large ugly GUI program (uses Gtk2), and I want the GUI keep active while background work is running. However, there are some complexed data structure that need to be accessed by both the GUI and worker thread, so I really wants a "real" thread that shares everything by default, but not copying. Remember I'm saying this without the benefit of your knowledge of the actual application, but in general, a GUI doesn't need access to large volume of shared data. Gui's by their nature are for presentation, and presenting large volumes of data to the user means they have to scroll up and down or side to side trying to find anything of interest. Two representative scenarios come to mind: In both the above scenarios, the intuitive solution is to load all the data into a single, huge, shared data structure so that whatever thread needs access to any part of it, has direct access to it. But the reality is, that this intuition is often naive and misleading. Regardless of whether you are using ithreads explicitly-shared-only model; or C's everything-shared model. This because if all threads have access to all the data, it means that every thread has to employ locking to every read and write. And the overhead of locking is the biggest barrier to efficient use of threading. The way to avoid that overhead, is to avoid sharing data that doesn't need to be shared. Rather than giving all threads access to all the data; give each thread access to only that data it needs to process. In that way, each thread can be written in the knowledge that only it has access to it's particular subset of the data, and therefore can dispense with locking entirely. And the benefits of that for both the simplicity of the coding, and the performance of the algorithm, are profound. Again this is true whether we're talking about Perl threading, or any other language. Not all algorithms fit the above observations, but many more do than don't. Though sometimes it requires you to look at the problem with fresh eyes to see the no-sharing, therefore lock-free, solution. I too wish that the threads::shared mechanism was lighter, and I have recently begun to get inklings of a possibility that might allow it, or something like it, to be so--but don't hold your breath. As things stand, there are often--even usually--ways of approaching most data sharing problems that work with the strengths of the ithreads model rather than against them. If you have particular real-world scenarios that you are finding the sharing model a particular limitation, please share [sic] them (in detail). Whilst I make no promises of a ready solution, the more eyes that see the problems, the more likely a solution will be forthcoming. And even if none is, having known, real limitations documented may lead to better things down the road. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |