Jackey's 感悟

Do Research

Monthly Archives: 二月 2011

Polly Matzinger and her Danger Model

From Evernote:

Polly Matzinger

Clipped from: http://en.wikipedia.org/wiki/Polly_Matzinger

Polly Matzinger

From Wikipedia, the free encyclopedia
220px-Polly_&_Annie.jpg
Polly & Annie

Polly Celine Eveline Matzinger (born 21 July 1947) is an iconoclastic scientist who proposed a novel explanation of how theimmune system works, called the danger model.

Contents

[hide]

[edit]Early years

Polly Matzinger took to science from an unusual background career path which included stints as a Playboy Bunny at a Playboy Club in Denver, a bar waitress, a jazzmusician, a carpenter and dog trainer. In 1974 Polly Matzinger had dropped in and out of college for years and worked at various jobs before ending up waitressing at a bar frequented by faculty from the University of California, at Davis and here she met Professor Robert Schwab, the head of the University’s wildlife program who noticed her talent and persuaded her to take to science.[1]

She eventually went to the University of California, San Diego for her Ph.D., did post-doctoral work at the University of Cambridge, and was a scientist at the Basel Institute for Immunology before coming to the National Institutes of Health in Bethesda, Maryland.

[edit]Ghost Lab at NIAID

Polly Matzinger is now a section head at the National Institute of Allergy and Infectious Diseases. Matzinger and her coworkers refer to the lab’s name as the ‘Ghost Lab’ when listing their affiliation in papers. The nickname was given to the lab by her colleagues when Matzinger first arrived at the NIH because she spent the first nine months studying a new field (Chaos Theory) that she thought might apply to the immune system, and the lab sat empty. The formal name of her laboratory is the T-Cell Tolerance and Memory Section of the Laboratory of Cellular and Molecular Immunology. The ghost lab now hosts 3 post-doctoral researchers .[1] From this knowledge pool, approximately 0-3 original research articles are published a year, including original research articles and theoretical pieces. A majority of the publications are her taken-author published works, theoretical in nature and published in very highly cited journals. [2]

[edit]The Danger Model

The self-non-self model, the predominant model in immunology since the 1950s, began to encounter problems in the late 1980s when immunologists began to recognize that T-cells depend on other cells to pick up and then present the things to which they will respond — and that the T-cell response depends on whether the other cell (known as antigen-presenting cells) is sending activation signals to the T-cells.

In 1989, drawing on the ideas of Thomas Kuhn, Charles Janeway proposed that the old immunological paradigm had reached the limits of its usefulness—or, as he described it, the asymptote of the increase in knowledge which it had brought. Janeway argued that the innate immune system was the real gatekeeper of whether the immune system responded or did not respond. He also argued that the innate immune system used ancient pattern-recognition receptors to make these decisions – recognizing a pathogen by its unchanging characteristics.

[edit]Danger signals

In a 1994 article entitled "Tolerance, Danger and the Extended Family", Matzinger went several steps further by laying out the idea that antigen-presenting cells respond to "danger signals" – most notably from cells undergoing injury, or stress or "bad cell death" (as opposed to apoptosis, controlled cell death). The alarm signals released by these cells let the immune system know that there is a problem requiring an immune response. She argued that T-cells and the immune response they orchestrate occurs not because of a neonatal definition of "self", as in the previous model, nor because of ancient definitions of pathogens, as in Janeway’s argument, but due to a dynamic and constantly-updated response to danger as defined by cellular damage.

[edit]Scope

The Danger Model is quite broad, covering topics as diverse as transplantation, maternal/fetal immunity, autoimmunity, cancer treatments, and vaccines, but Matzinger points out that although it offers an explanation of how an immune response is triggered and how it ends, it does not (yet) offer an explanation of why the immune system responds in different ways to different situations. She hypothesizes that tissues send signals to the immune system that determine the immune response appropriate for that tissue, and her lab is now working on experiments to test that hypothesis.

The Danger Model has not won universal acceptance. Some immunologists, following Janeway’s ideas more directly, believe that the immune response is mainly fueled by innate evolutionarily-conserved "pattern recognition receptors" which recognize patterns expressed by microbes such as bacteria, and do not see cell death in the absence of pathogens as a primary driver of immune response. These ideas however, do not explain how the immune system rejects transplants (most well-done transplants are not covered in bacteria), or tumors, or induce autoimmune diseases.

[edit]Pattern recognition and a tissue-driven immune system

Recently, Seong and Matzinger have suggested that the "patterns" that the immune system recognizes on bacteria are not as different from the alarm signals released by damaged cells as one might have thought. They suggested that, because life evolved in water, the hydrophobic portions (Hyppos) of molecules are normally hidden in the internal parts of molecules or other structures (like membranes) and that the sudden exposure of a Hyppo is a sure sign that some injury or damage has occurred. They suggested that these are the most ancient alarm signals, that they are recognized by evolutionarily ancient systems of repair and remodeling, and that the modern immune system piggy-backed on this ancient system. Thus bacteria and other organisms may have very similar alarm systems. They describe these ancient signals as Danger-associated molecular patterns, or DAMPs.

In a recent article in Nature Immunology [3], Matzinger makes a case for what she now views as the most important implication of the Danger Model: that the tissues of the body are a large part of what drive immune response. She argues that immunologists have had overly simplistic and schematic ideas about immune response because of the limits of their assays, and that organs are likely to induce immune responses that are best-suited to defending the organ from the damage of microbesbut also from the damage of the immune system itself. She also asserts that the relationship of the immune system to commensal bacteria remains poorly understood but is likely to be important.

Matzinger argues that the idea of DAMPs may explain why Toll-like receptors seem to respond both to external and endogenous signals (while acknowledging controversy over this issue). By emphasizing her theory that the tissues drive the nature of the immune response (i.e., the "what type" rather than the "whether" of immune response), Matzinger describes a dynamic immune system with complex webs of signalling, rather than an immune system that can be explained by a simple and easily reducible set of molecular signals that initiate response, or by a small set of cells (e.g., "regulatory" T-cells) which shut it down.

[edit]Challenges to Matzinger’s theories

There is now a growing body of work on "regulatory T-cells" which argues that immune activity is stopped by a special subset of T-cells. These ideas challenge several of the key specifics of Matzinger’s model.

A student sitting in an immunology class today will likely hear many phrases coined by Matzinger (like "professional antigen-presenting-cell" or "danger signal" or "DAMPs" (damage associated molecular patterns") but will often hear them in the framework of a self-non-self explanation of immunity. Other immunologists have often adapted parts of Matzinger’s ideas without adopting the Danger Model as a theoretical framework.

Indeed, in an era of increasingly detailed molecular work, many immunologists simply avoid constructing an alternative broad theory of immune function. Others believe that the immune system is not a single system at all, and is instead a set of mechanisms "cobbled together" by evolution.[4] If this is true, no single theory can explain the function of the system as a whole. For both of these reasons, Matzinger has had to defend her larger theory, but also has had to defend the value of grand theory itself.

[edit]Past and current work with dogs

In one of her first publications, she appeared to have a dog as a coauthor for a paper for the Journal of Experimental Medicine[5]. As Ted Anton described the decision in his book Bold Science, "Refusing to write in the usual scientific passive voice (‘steps were taken’) and too insecure to write in the first person (‘I took the steps’), she instead invented [a] coauthor": her Afghan Hound, Galadriel Mirkwood.[2] Once discovered, papers on which she was a major author were then barred from the journal until the editor died and was replaced by another.

Although no dogs have been coauthors of any of her recent papers, she is an avid sheepdog trainer, and, with her two Border Collies, Charlie and Lily, was on the team that represented the United States at the 2005 World Sheepdog Finals in Tullamore, Ireland.

[edit]Publications

[edit]Films

  • Immunity: the inside story. Matzinger P and André Trauneker (1986) (video, 13 min) Award winning animated film for lay people describing the events involved in clearing an influenza infection. Translated into German, French, Spanish. Hoffman La Roche studio, Basel, Switzerland
  • A quick look at tissue rejection. Matzinger P. (1991) (Video, 2 min) Animated Film for lay people describing the events that result in rejection of a skin graft. Commissioned by the National Association of Science Writers for a meeting of television producers. NIH special events department and Capitol Studios
  • Death By Design.[3] Peter Friedman and Jean-François Brunet (1995) (Film, 73 minutes) Award winning Film on apoptotic cell death that features the work of six scientists. P Matzinger, R Levy-Montalcini, M Raff, P Golstein, KM Debatin, R Horowitz

[edit]External links

[edit]References

  1. ^ Curriculum vitae
  2. ^ Anton, Ted. Bold Science: Seven Scientists Who Are Changing Our World. New York: WH Freeman, 2000.
  3. ^ http://www.strange-attractions.com/films/death-by-design/ (Death by Design home page)

Categories: Immunologists | Women biologists | Living people | 1947 births

Using Nature’s Ideas to Solve Our Problems

From Evernote:

Using Nature’s Ideas to Solve Our Problems

Clipped from: http://sciencecareers.sciencemag.org/career_development/previous_issues/articles/2870/using_nature_s_ideas_to_solve_our_problems

The Job Market

Using Nature’s Ideas to Solve Our Problems

By Uwe Aickelin

February 20, 2004

It turned out that [immunologists] were not aware that [their discipline] was a source of inspiration to mathematicians!

BACK TO THE FEATURE INDEX

Editor’s note: Uwe Aickelin didn’t train as a typical mathematician, nor biologist, yet he now finds himself at the heart of a project that mixes the two. While following his love for mathematics, he came across concepts inspired by the natural world and became hooked on these ideas.

I started out as an undergraduate student in business science at the University of Mannheim in Germany, my home country. This degree covers all aspects of business and management studies, including marketing, finance, law, economics, and production scheduling. I chose business science at the time because I wanted to study something worthwhile that would also lead to a well-paid job. However, my true passion had always been mathematics, so whenever I could, I picked options that were related to mathematical subjects. One such topic was operational research, which investigates how to model business situations mathematically in order to make the best decisions, subject to certain criteria and limited resources.

If It Works in Nature, Why Not in Business?

I was offered the chance to specialise in this area with a master’s at the University of Wales, Swansea, during which I learnt about those algorithms that are borrowed from the sphere of artificial intelligence to solve the more complex problems. With one such algorithm, evolutionary computation, a number of random solutions to a problem are created and subsequently allowed to "breed," thereby creating more solutions. This, together with a Darwinian "survival of the fittest" amongst all solutions and an occasional "mutation," eventually leads to better and better solutions. I was hooked by this approach, as it seemed simple yet powerful. After all, if it works in nature, why not in business? This is a motto I would come back to again and again in my career.

So I decided to undertake a Ph.D. in Swansea to get to know these algorithms a bit better. I chose Kathryn Dowsland as my supervisor, both for her expertise in the area and as someone I thought I would get along with very well. I would strongly advise any prospective Ph.D. student to meet their supervisor a few times before starting, as a mutual understanding and respect is probably more important than the exact topic of the Ph.D. My own project was to use evolutionary algorithms to optimise solutions to multiple-choice problems, such as which nurse should be allocated to which shift in a hospital.

Coming to the end of my Ph.D. in 1999, I was still contemplating entering the world of business as a management consultant, but I had started to enjoy the world of research. In the end I decided on a lectureship in operational research in the School of Mathematics at the University of the West of England ( UWE) in Bristol.

When making this choice, I had to turn down a postdoc. Even though a lectureship is often seen as the Holy Grail for young researchers, I actually found the choice difficult. I knew that going for a lectureship straight away would be more of a challenge as well as more risky in the long run. Choosing the postdoc route may mean that you effectively enter the profession later, but it leaves you more space and time to build up a good publication record so that you might actually end up in a better position a few years down the line.

Still, I took the plunge and met my first challenge as a lecturer: teaching! Although I had taught the occasional lab class before and UWE was running support classes for new lecturers, I found my first year of teaching very difficult and time-consuming. But it was through my teaching that I first became interested in the biological concept–danger theory–that is behind my current project.

I gave my students an investigation of so-called artificial immune systems (AIS) as a piece of coursework. AIS are similar to evolutionary algorithms. However, rather than borrowing ideas from evolution and Darwin, they draw on concepts related to the human immune system.

One of my students, Steve Cayzer, who unbeknownst to me held a Ph.D. in biological sciences, did a much better job than my average student, and we found that we could devise AIS algorithms that were useful for solving complex data-mining problems. Consider the example of renting a video. To make sure that you pick a movie you have never seen and will like, what you really need are a couple of friends who know your tastes and have seen a wide range of films. But if your friends aren’t around, you could always turn to an AIS for recommendations.

How? Well, your tastes would be mathematically modelled as "antigens" (or targets) and then matched against possible "antibodies," i.e., movies that have previously been entered into a database according to the likes and dislikes of other people. In the human immune system, the antibodies would kill the antigens, but in the AIS, they can be used to predict films you would like.

Responding to Danger Signals

This led me to ask immunologists around UWE what they thought of AIS. It turned out that they were not aware that immunology was a source of inspiration to mathematicians! After some interesting discussions I enquired about what was hot in immunology and was given a paper entitled "The Danger Theory." This theory challenges the traditional idea that the body attacks intruders because they are recognised as foreign to the body, arguing that what the immune system responds to is a signal of danger instead. I immediately saw the potential benefits of applying this theory to the design of an AIS that would provide an intrusion detection system (IDS) for computer security.

Although current AIS show great potential for tackling intruders, they have been held back by the huge amount of processing required by traditional models of natural immune systems. If you consider using the classical paradigm to protect a computer network against everything that is foreign to it, it means mapping the rest of the world! The danger theory provides brand-new ideas upon which to design AIS.

Through our danger theory project we are trying to construct effective artificial defence mechanisms that could be used for computer security as well as financial fraud detection and network fault management. The project got funded by the Engineering and Physical Sciences Research Council and is the largest of its type in the United Kingdom.

Writing the proposal was difficult, as it meant learning a lot of the immunological phrases and vocabulary. I was greatly helped by Julie McLeod, an immunologist at UWE, and by my student Steve Cayzer, who, knowing both sides of the coin, was an excellent translator. Finally, other experts I met at conferences and workshops–immunologists from the University of Bristol and IDS experts from University College London, Hewlett-Packard, and ECSC, a leading computer-security company–also got involved in the project. So my one piece of advice on writing proposals for multidisciplinary projects is to ask the experts. OK, it will take you some time and effort to understand what they are talking about, but it is much better than trying to do it yourself and second-guessing.

I now work at the University of Nottingham, where I am the principal investigator of the danger theory project, which means leading a team of 10. Hence I am busier than ever! The project will last for another 3 years, and I look forward to discovering more about using nature’s ideas to solve our problems.

If you would like to find out more about Uwe Aickelin’s work or get in touch with him, see his Web site. .

EPSRC Newsline magazine, Issue 28, p4, 2004. Sensing Danger

From Evernote:

EPSRC Newsline magazine, Issue 28, p4, 2004. Sensing Danger

Clipped from: http://www.cs.nott.ac.uk/%7Euxa/papers/newsline_danger.html

EPSRC Newsline magazine, Issue 28, p4, 2004.

Sensing Danger

Could immunology-inspired research protect your computer?

As adventurous research goes, taking a controversial idea from immunology and applying it to computing is setting your sights rather high. Yet it was exactly this streak of ambition that caused EPSRC to recently award funding to Dr Uwe Aickelin of the University of Nottingham under its ‘adventure’ call. Dr Aickelin’s plan is to apply a concept from immunology, known as ‘Danger Theory’, to the problem of detecting people who might be tampering with your computer system.

Dr Aickelin first became interested in the idea for the project after his student, Steve Cayzer, investigated so-called ‘Artificial Immune Systems’ (AIS). Aickelin and Cayzer found that they could devise AIS algorithms that were useful for solving complex data mining problems. This led him to ask immunologist Julie McLeod what she and her colleagues thought of AIS: “It turned out that they had never heard of the area!” says Dr Aickelin, “after some interesting discussions I asked Julie what is currently hot in immunology and she gave me a paper entitled ‘The Danger Theory.’” This controversial theory suggests that the traditional idea that the body differentiates between self and non-self is wrong and that instead the immune system identifies ‘danger’ and then responds to it. Dr Aickelin immediately saw the potential benefits of an Intruder Detection System (IDS) using Danger Theory-based AIS.

While current Artificial Immune Systems show great potential for tackling intruders they have been held back by the huge amount of processing involved in following traditional models of natural immune systems: “Consider using the classical paradigm to protect a computer network against non-self: It means mapping the rest of the world!” says Dr Aickelin. “This project will try and overcome this restriction by using ideas based on Danger Theory. This should allow the construction of effective artificial defence mechanisms in areas such as computer security, financial fraud detection, network fault management or intrusion detection.” The project has attracted IDS experts from UCL, immunologists from Bristol, heuristic optimisation researchers from Nottingham and support from Hewlett Packard and ECSC, a leading computer security company. Dr Aickelin believes that despite the adventurous nature of the research it’s bound to produce valuable results: “The immunological results will stand regardless of the IDS and also regardless of whether the Danger Theory itself is ultimately accepted by immunologists.”

Contacts

For more on this new research contact Dr Uwe Aickelin uwe.aickelin

Information on the adventure call is available at http://www.epsrc.ac.uk

Danger Theory: The Missing Link Between Artificial Immune Systems And Intrusion

From Evernote:

Danger Theory: The Missing Link Between Artificial Immune Systems And Intrusion

Clipped from: http://www.cs.nott.ac.uk/%7Euxa/papers/aisb_danger.html

Danger Theory: The Missing Link Between Artificial Immune Systems And Intrusion Detection

Creating a next generation Intrusion Detection System based on the latest Immunological Theories.

AISB Quarterly, Issue 115, pp 1-2, 2004.

The central challenge with computer security is determining the difference between normal and potentially harmful activity. For half a century, developers have protected their systems by coding rules that identify and block specific events. However, the nature of current and future threats in conjunction with ever larger IT systems urgently requires the development of automated and adaptive defensive tools.

A promising solution is emerging in the form of Artificial Immune Systems (AIS): The Human Immune System (HIS) can detect and defend against harmful and previously unseen invaders, so can we not build a similar Intrusion Detection System (IDS) for our computers? Presumably, those systems would then have the same beneficial properties as HIS like error tolerance, adaptation and self-monitoring.

Current AIS have been successful on test systems, but the algorithms were unable to scale up to real-world requirements. This is caused by their reliability on self-nonself discrimination, as stipulated in classical immunology. However, immunologist are increasingly finding fault with traditional self-nonself thinking and a new ‘Danger Theory’ (DT) is emerging.

This new theory suggests that the immune system reacts to threats based on the correlation of various (danger) signals and it provides a method of ‘grounding’ the immune response, i.e. linking it directly to the attacker. Little is currently understood of the precise nature and correlation of these signals and the theory is a topic of hot debate. It is the aim of this research to investigate this correlation and to translate the DT into the realms of computer security, thereby creating AIS that are no longer limited by self-nonself discrimination. It should be noted that we do not intend to defend this controversial theory per se, although as a deliverable this project will add to the body of knowledge in this area. Rather we are interested in its merits for scaling up AIS applications by overcoming self-nonself discrimination problems.

With our growing understanding of cellular components involved with apoptosis, it will be possible to compare the differential proteomic profile between necrotic (‘bad’) and apoptotic (‘good’ or ‘planned’) cell death, particularly with respect to Antigen Presenting Cells (APCs) activation. A vital necessity will be in maintaining the physiological relevance of the system to be utilised, so that the power of the DT in protecting against false positives will be preserved.

In essence, it is thought that apoptosis has a suppressive effect and necrosis a stimulatory immunological effect, although they might not actually as distinct as currently thought. In the IDS context, this can be read in two ways: either the necrotic signals act to say that the previous pattern of apoptotic signals is dangerous or the apoptotic signals indicate that the necrotic signals are a false alarm.

A variety of contextual clues may be essential for a meaningful ‘danger signal’, and immunological studies will provide a framework of ideas as to how ‘danger’ is assessed in the HIS. Such ideas can be fruitfully applied to the AIS arena. In the latter context, the danger signals should show up after limited attack to minimise damage and therefore have to be quickly and automatically measurable. Once the danger signal has been transmitted, the AIS can react to those artificial antigens that are ‘near’ the emitter of the danger signal. This allows the AIS to pay special attention to dangerous components and would have the advantage of detecting rapidly spreading viruses or scanning intrusions at an early stage preventing serious damage. See Figure 1 for a graphical illustration.

The Danger Theory Model

Figure 1: The Danger Theory Model.

This 3 year £657k project will start 1 January 2004 and is funded by the UK’s Engineering and Physical Sciences Research Council, with further support from Hewlett Pacckard Labs Bristol and ECSC Computer Security Bradford. For more information please contact the Principal Investigator:

Dr Uwe Aickelin

School of Computer Science

University of Nottingham

uxa

http://www.aickelin.com

《软件调试的艺术》学习笔记——GDB使用技巧摘要(4)——Pthread线程调试

Unix下最普遍的线程包是POSIX标准的Pthreads。Pthreads使用的抢占式线程管理策略,程序中的一个线程可能在任何时候被另一个线程中断。所以,使用Pthreads开发的应用程序有些错误不太容易重现。

GDB线程相关命令汇总

  • info threads 给出关于当前所有线程的信息
  • thread n 改为线程n,或者说是进入线程n的栈中进行观察
  • break line_num thread n 表示当线程n到达源码行line_num时停止执行
  • break line_num thread n if expression 上一命令增加条件断点而已

加入怀疑线程之间有死锁,可以用gdb进行调试定位。流程大致是:

  1. 用gdb启动或者插入待调试程序
  2. 当程序挂起时候,通过按下Ctrl+C组合键中断它;
  3. 这个时候用info threads查看所有线程都在干嘛,然后找到自己的工作线程(注意排除main线程和pthreads的管理线程)
  4. 分别查看自己的工作线程在干嘛,用bt(backtrace)查看对应的帧,记得用thread n切换进入对应线程的帧
  5. 关注像__pthread_wait_for_restart_signal()和lock等函数,如果有源码的话,会比较方便地定位到具体的问题代码位置

下面是一个简单的例子。如果在worker线程里面,上锁和解锁没有匹配,则会发生死锁

// finds the primes between 2 and n; uses the Sieve of Eratosthenes,
// deleting all multiples of 2, all multiples of 3, all multiples of 5,
// etc.; not efficient, e.g. each thread should do deleting for a whole
// block of values of base before going to nextbase for more 

// usage:  sieve nthreads n
// where nthreads is the number of worker threads

#include      <stdio.h>
#include      <math.h>
#include      <pthread.h>

#define MAX_N     100000000
#define MAX_THREADS  100

// shared variables
int nthreads,  // number of threads (not counting main())
    n,  // upper bound of range in which to find primes
    prime[MAX_N+1],  // in the end, prime[i] = 1 if i prime, else 0
    nextbase;  // next sieve multiplier to be used

int work[MAX_THREADS];  // to measure how much work each thread does,
                        // in terms of number of sieve multipliers checked

// lock index for the shared variable nextbase
pthread_mutex_t nextbaselock = PTHREAD_MUTEX_INITIALIZER;

// ID structs for the threads
pthread_t id[MAX_THREADS];

// "crosses out" all multiples of k, from k*k on
void crossout(int k)
{  int i;

   for (i = k; i*k <= n; i++)  {
      prime[i*k] = 0;
   }
}

// worker thread routine
void *worker(int tn)  // tn is the thread number (0,1,...)
{  int lim,base;

   // no need to check multipliers bigger than sqrt(n)
   lim = sqrt(n);

   do  {
      // get next sieve multiplier, avoiding duplication across threads
      pthread_mutex_lock(&nextbaselock);
      base = nextbase += 2; 
      pthread_mutex_unlock(&nextbaselock); 

         if (base <= lim)  {
         work[tn]++;  // log work done by this thread
         // don't bother with crossing out if base is known to be
         // composite
         if (prime[base])
            crossout(base);
      }
      else return;
   } while (1);
}

main(int argc, char **argv)
{  int nprimes,  // number of primes found 
       totwork,  // number of base values checked
       i;
   void *p;

   n = atoi(argv[1]);
   nthreads = atoi(argv[2]);
   for (i = 2; i <= n; i++)
      prime[i] = 1;
   crossout(2);
   nextbase = 1;
   // get threads started
   for (i = 0; i < nthreads; i++)  {
      pthread_create(&id[i],NULL,(void *) worker,(void *) i);
   }

   // wait for all done
   totwork = 0;
   for (i = 0; i < nthreads; i++)  {
      pthread_join(id[i],&p);
      printf(" %d
           values of base done
          \n
          ",work[i]);
      totwork += work[i];
   }
   printf("
          %d 
          total values of base done
          \n
          ",totwork);

   // report results
   nprimes = 0;
   for (i = 2; i <= n; i++)
      if (prime[i]) nprimes++;
   printf("the number of primes found was %d
          \n
          ",nprimes);

}

阅读余下文章

Pthreads调试

// finds the primes between 2 and n; uses the Sieve of Eratosthenes,
// deleting all multiples of 2, all multiples of 3, all multiples of 5,
// etc.; not efficient, e.g. each thread should do deleting for a whole
// block of values of base before going to nextbase for more 

// usage:  sieve nthreads n
// where nthreads is the number of worker threads

#include <stdio.h>
#include <math.h>
#include <pthread.h>

#define MAX_N 100000000
#define MAX_THREADS 100

// shared variables
int nthreads,  // number of threads (not counting main())
    n,  // upper bound of range in which to find primes
    prime[MAX_N+1],  // in the end, prime[i] = 1 if i prime, else 0
    nextbase;  // next sieve multiplier to be used

int work[MAX_THREADS];  // to measure how much work each thread does,
                        // in terms of number of sieve multipliers checked

// lock index for the shared variable nextbase
pthread_mutex_t nextbaselock = PTHREAD_MUTEX_INITIALIZER;

// ID structs for the threads
pthread_t id[MAX_THREADS];

// "crosses out" all multiples of k, from k*k on
void crossout(int k)
{  int i;

   for (i = k; i*k <= n; i++)  {
      prime[i*k] = 0;
   }
}

// worker thread routine
void *worker(int tn)  // tn is the thread number (0,1,...)
{  int lim,base;

   // no need to check multipliers bigger than sqrt(n)
   lim = sqrt(n);

   do  {
      // get next sieve multiplier, avoiding duplication across threads
      pthread_mutex_lock(&nextbaselock);
      base = nextbase += 2;
      pthread_mutex_unlock(&nextbaselock);
      if (base <= lim)  {
         work[tn]++;  // log work done by this thread
         // don't bother with crossing out if base is known to be
         // composite
         if (prime[base])
            crossout(base);
      }
      else return;
   } while (1);
}

main(int argc, char **argv)
{  int nprimes,  // number of primes found 
       totwork,  // number of base values checked
       i;
   void *p;

   n = atoi(argv[1]);
   nthreads = atoi(argv[2]);
   for (i = 2; i <= n; i++)
      prime[i] = 1;
   crossout(2);
   nextbase = 1;
   // get threads started
   for (i = 0; i < nthreads; i++)  {
      pthread_create(&id[i],NULL,(void *) worker,(void *) i);
   }

   // wait for all done
   totwork = 0;
   for (i = 0; i < nthreads; i++)  {
      pthread_join(id[i],&p);
      printf("%d values of base done\n",work[i]);
      totwork += work[i];
   }
   printf("%d total values of base done\n",totwork);

   // report results
   nprimes = 0;
   for (i = 2; i <= n; i++)
      if (prime[i]) nprimes++;
   printf("the number of primes found was %d\n",nprimes);

}
// finds the primes between 2 and n; uses the Sieve of Eratosthenes,
// deleting all multiples of 2, all multiples of 3, all multiples of 5,
// etc.; not efficient, e.g. each thread should do deleting for a whole
// block of values of base before going to nextbase for more 

// usage:  sieve nthreads n
// where nthreads is the number of worker threads

#include <stdio.h>
#include <math.h>
#include <pthread.h>

#define MAX_N 100000000
#define MAX_THREADS 100

// shared variables
int nthreads,  // number of threads (not counting main())
    n,  // upper bound of range in which to find primes
    prime[MAX_N+1],  // in the end, prime[i] = 1 if i prime, else 0
    nextbase;  // next sieve multiplier to be used

int work[MAX_THREADS];  // to measure how much work each thread does,
                        // in terms of number of sieve multipliers checked

// lock index for the shared variable nextbase
pthread_mutex_t nextbaselock = PTHREAD_MUTEX_INITIALIZER;

// ID structs for the threads
pthread_t id[MAX_THREADS];

// "crosses out" all multiples of k, from k*k on
void crossout(int k)
{  int i;

   for (i = k; i*k <= n; i++)  {
      prime[i*k] = 0;
   }
}

// worker thread routine
void *worker(int tn)  // tn is the thread number (0,1,...)
{  int lim,base;

   // no need to check multipliers bigger than sqrt(n)
   lim = sqrt(n);

   do  {
      // get next sieve multiplier, avoiding duplication across threads
      pthread_mutex_lock(&nextbaselock);
      base = nextbase += 2;
      pthread_mutex_unlock(&nextbaselock);
      if (base <= lim)  {
         work[tn]++;  // log work done by this thread
         // don't bother with crossing out if base is known to be
         // composite
         if (prime[base])
            crossout(base);
      }
      else return;
   } while (1);
}

main(int argc, char **argv)
{  int nprimes,  // number of primes found 
       totwork,  // number of base values checked
       i;
   void *p;

   n = atoi(argv[1]);
   nthreads = atoi(argv[2]);
   for (i = 2; i <= n; i++)
      prime[i] = 1;
   crossout(2);
   nextbase = 1;
   // get threads started
   for (i = 0; i < nthreads; i++)  {
      pthread_create(&id[i],NULL,(void *) worker,(void *) i);
   }

   // wait for all done
   totwork = 0;
   for (i = 0; i < nthreads; i++)  {
      pthread_join(id[i],&p);
      printf("%d values of base done\n",work[i]);
      totwork += work[i];
   }
   printf("%d total values of base done\n",totwork);

   // report results
   nprimes = 0;
   for (i = 2; i <= n; i++)
      if (prime[i]) nprimes++;
   printf("the number of primes found was %d\n",nprimes);

}

Keyboard shortchuts for Thunderbird

About keyboard shortcuts

In Thunderbird, keyboard shortcuts are context sensitive. That is, they vary according to the area of the Thunderbird interface that is currently “active”. For example, when a message is selected in the message list, the Cut, Copy and Paste keyboard shortcuts are disabled (because it doesn’t make sense to cut and paste text into the message list). Similarly, if you select text while you are reading a message, the Copy shortcut is available, but not the Cut or Paste shortcuts (because while it makes sense to copy text from a message you are reading, it doesn’t make sense to paste text into or cut text from a message you are reading).

Sometimes the keyboard shortcut functions themselves vary depending on the part of the Thunderbird interface that is active. For example, if you are writing a message, the Ctrl + A keyboard shortcut selects all the text in the message. However, if a message is highlighted in the message list, Ctrl + A selects all the messages in the message list.

Shortcut keys and operating systems

  • On Windows and Linux, the shortcut accelerator key is usually the Ctrl key
  • On Mac OS X, the shortcut accelerator key is usually the Command (⌘) key
  • On Mac OS X laptops, you must hold down the fn key to enable a function key

Message functions

New message (default format) Ctrl + M (Windows), Command + N (Mac)
New message (non-default format) Shift + Ctrl + M (Windows), Shift + Command + N (Mac)
Open message (in new window or tab) Ctrl / Command + O
Print Ctrl / Command + P
Copy Ctrl / Command + C
Move to previous folder Again Ctrl / Command + Alt / Option + M
Delete Del
Delete bypassing trash Shift + Del
Select All (messages or text in a message) Ctrl / Command + A
Select Thread Ctrl / Command + Shift + A
Undo Ctrl / Command + Z
Redo Ctrl / Command + Y
Edit Message as New Ctrl / Command + E
Expand All Threads *
Collapse All Threads \
Quick Filter Ctrl / Command + F
Find Text in Current Message Ctrl / Command + F, Ctrl / Command + F
Find Again in Current Message Ctrl / Command + G, F3
Find Previous in Current Message Ctrl / Command + Shift + G, Shift + F3
Search All Messages in Folder Ctrl / Command + Shift + F
Caret Browsing F7
Close window or tab Ctrl / Command + W
Forward Message Ctrl / Command + L
Get New Messages for Current Account Ctrl / Command + T, F9 (Linux / Mac), F5 (Windows)
Get New Messages for All Accounts Ctrl / Command + Shift + T
Increase Text Size Ctrl / Command + +
Decrease Text Size Ctrl / Command + –
Restore Text Size Ctrl / Command + 0 (zero)
Add/Remove Tag 1 to 9
Remove All Tags from Message 0 (zero)
Mark Message as Read/Unread M
Mark Thread as Read R
Mark All Read Shift + C
Mark as Read By Date C
Mark as Junk J
Mark as Not Junk Shift + J
Add Star S
Archive A
View Message Source Ctrl / Command + U
Reply to Message (sender only)(default format) Ctrl / Command + R
Reply to Message (sender only)(non-default format) Shift + Ctrl / Command + R
Reply to All in Message (all recipients)(default format) Ctrl / Command + Shift + R
Reply to All in Message (all recipients)(non-default format) Shift + Ctrl / Command + Shift + R
Reply to List Ctrl / Command + Shift + L
Save Message as File Ctrl / Command + S
Search Messages Ctrl / Command + Shift + F (Windows / Mac), Shift + F (Linux)
Send and Receive All Messages Ctrl / Command + T, F5
Stop Esc
Exit Ctrl / Command + Q

Newsgroup Messages

Expand Collapsed Thread right arrow
Collapse Expanded Thread left arrow
Ignore or Unignore Thread K
Ignore or Unignore Subthread Shift + K
Watch Thread W

Moving around Thunderbird

Toggle Message Pane F8
Go to Next Message F
Go to Next Unread Message N
Go to Previously Viewed Message [
Go to Next Viewed Message ]
Go to Next Unread Thread T
Go to Previous Message B
Go to Previous Unread Message P
Move to Next Mail Pane F6
Move to Search Bar (Global Search) Ctrl / Command + K
Help Ctrl / Command + ?
Minimize Ctrl / Command + M
Mail & Newsgroups Ctrl / Command + 1
Saved Files Ctrl / Command + J
Address Book Ctrl / Command + Shift + B
Preferences Ctrl / Command + 1
Hide Thunderbird Ctrl / Command + H
Hide Other Windows Ctrl / Command + Alt / Option + H
Quit Ctrl / Command + Q

Writing messages

New message Command + N (Mac), Ctrl + M (Windows)
Copy Ctrl / Command + C
Cut Ctrl / Command + X
Paste Ctrl / Command + V
Paste as quotation Ctrl / Command + Shift + O/
Paste without formatting Ctrl / Command + Shift + V
Move / Copy Again Ctrl / Command + Shift + M
Select All (text in a message) Ctrl / Command + A
Undo Ctrl / Command + Z
Redo Ctrl / Command + Y
Delete current word Ctrl + Del (Windows)
Delete previous word Ctrl + Backspace (Windows)
Find Text in Current Message Ctrl / Command + F
Find Again in Current Message Ctrl / Command + G, F3
Find Previous in Current Message Ctrl / Command + Shift + G, Shift + F3
Increase Text Size Ctrl / Command + +
Decrease Text Size Ctrl / Command + –
Restore Text Size Ctrl / Command + 0 (zero)
View Message Source Ctrl / Command + U
Save Draft Ctrl / Command + S
Send Message Now Ctrl / Command + Enter / Return
Send Message Later Ctrl / Command + Shift + Enter / Return
Add Additional Recipient Alt / Option + down arrow

cite from http://support.mozillamessaging.com/zh-CN/kb/Keyboard+shortcuts

Order of authorship

Order of authorship

The first author is primarily responsible for collecting and analyzing data, and writing
The last one, an established investigator, assumes the overall responsibility for the study
The middle authors are listed according to their order of importance to the study.

Another more strict definition of authorship is as follows:

Authorship credit should be based on
substantial contributions to conception and design, or acquisition of data, or analysis and interpretation of data;
drafting the article or revising it critically for important intellectual content;
final approval of the version to be published.

Authors should meet conditions 1, 2, and 3. Those who have participated in certain substantive aspects of the research project should be acknowledged or listed as contributors. Acquisition of funding, collection of data, or general supervision of the research group, alone, does not justify authorship.

Each author should have sufficiently participated in the work to take public responsibilities for appropriate portions of the content. The corresponding author should ensure that all appropriate co-authors and no inappropriate co-authors are included on the paper. If there is plagiarism or other ethical problems, the corresponding author cannot hide behind or remain innocent.

《软件调试的艺术》学习笔记——GDB使用技巧摘要(3)——程序崩溃处理

  1. 程序为什么会崩溃
  2. 内存中的程序布局

当某个错误导致程序突然和异常地停止执行时,程序崩溃。迄今为止最为常见的导致程序崩溃的原因是试图在未经允许的情况下访问一个内存位置。硬件会感知这件事,并执行对操作系统的跳转。Unix系列的平台上,操作系统一般会宣布程序导致了段错误(seg
fault),并停止程序运行。在微软的windows系统上,对应的术语是一般保护错误(general protection
fault)。无论是哪个名称,硬件都必须支持虚拟内存,而且操作系统必须使用虚拟内存才会发生这个错误。虽然这是如今的通用计算机的标准,但是读者应记住,专用的小型计算机一般没有这种情况,比如用来控制机器的嵌入式计算机。

程序在内存中是如何分布的?

在Unix平台上,为程序分配的虚拟地址的布局通常如下:

.text

.data

.bss

未使用

env

这里虚拟地址0在最下方,箭头显示了其中两个组件(堆和栈)的增长方向,当它们增长时,消耗掉未使用的自由区域。各个部分的作用如下:

  • 文本区域(.text),由程序源代码中的编译器产生的机器指令组成。这一组件包括静态链接代码,包括做初始化工作然后调用main()的系统代码/usr/lib/crt0.o
  • .data 数据区域,包含在编译时分配的所有程序变量,即全局变量。如 int x = 5;
  • .bss 数据区域,包含的是存放未初始化数据的全局变量,如 int y;
  • 当程序在运行时从操作系统请求额外的内存时(例如,C语言中调用malloc,或者C++中的new),请求的内存在名为堆(heap)的区域中分配。如果堆空间不足,可以通过调用brk()来扩展堆(这正是malloc及相关函数所做的事情)
  • 栈区域(stack),是用来动态分配数据的空间。函数调用的数据(包括参数、局部变量和返回地址)都存储在栈上。每次进行函数调用时栈都会增长,每次函数返回到其调用者时栈都会收缩。
  • 上图没有显示程序的动态链接代码,它的位置与平台相关,但是它确实在某个地方存在,而且在每种操作系统上,虚拟内存中关于动态链接代码的地址是有规律的。
  1. int q[ 200 ] ;
  2. int main( void ) {
  3. int i,n, *p;
  4. p = malloc( sizeof ( int ) ) ;
  5. scanf( “%d” , &n) ;
  6. for (i = 0 ; i < 200 ; i++ )
  7. q[i] = i;
  8. printf ( “%x %x %x %x %x\n , main, q, p, &i, scanf) ;
  9. return 0 ;
  10. }

虽然上述程序本身作用不大,但是可以编写成一个工具来非正式地探索虚拟地址空间的布局。运行结果可能如下:

% a.out

5

80483f4 80496a0 9835008 bfb3abec 8048304

分别对应于文本区域、数据区域、堆、栈和动态链接函数位置。

另外可以通过查看这一过程的maps文件来得到程序在linux上的精确内存布局情况。加入进程号是21111,那么查看的文件应该是/proc/21111/maps

页的概念

虚拟地址空间是通过坐直成成为页(page)的块来查看的。在pentium硬件上,默认的页大小是4096字节。物理内存(包括RAM和ROM)也都是分成页来查看的。当程序被加载到内存中执行时,操作系统会安排程序的部分页存储在物理内存的页中。这些页成为被”驻留”,其余部分存储在磁盘上。

在执行期间的各个阶段,将需要一些当前没有驻留的程序页。当发生这种情况的时候,硬件会感知到,将控制权转移给操作系统。后者将所需页带到内存中,可能会替换掉当前驻留的另一个程序页(如果没有可用的自由内存页),然后将控制权返回给程序。如果有被驱逐的程序页,就会变成非驻留页,被存储在磁盘上。

为了管理所有这些操作,操作系统为每个过程设立了一个页表(page table)。(pentium的页表有一个层次结构,但是为了简单起见,假定只有一层,而且这里讨论的大多数内容都不是pentium特有的。)这一过程的每个虚拟页在表中都有对应的一个项(entry),其中包括如下信息:

  • 这个页在内存中或者磁盘上的当前物理位置。如果是在磁盘上,页表对应的项会指示页是非驻留的,可能包含一个指针,指向最终导致磁盘上的物理位置的一个列表。例如,它可能显示:程序的虚拟页12是驻留的,位于内存的物理页200中。
  • 该页的权限分为3种:读、写和执行

注意:操作系统不会将不完整的页分配给程序。例如,如果要运行的程序总共有10 000字节,如果完全加载,会占用3个内存页(3*4096),不会是占用2.5个页,因为页是虚拟内存系统能够操作的最小内存单元。这是调试时要记住的很重要的一点,因为这一点暗示了程序的一些错误内存访问不会触发段错误。换言之,在调试会话期间,不能这么想:”这行代码一定没有问题,因为它没有引起段错误。”

阅读余下文章

《软件调试的艺术》学习笔记——GDB使用技巧摘要(2)

command命令可以在每次发生断点的时候自动执行一系列命令,解放程序员的双手。
见示例:
(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just “end”
>silent
>printf “fibonacci was passed %d.\n”, n
> continue
>end
(gdb) run
Starting program: fibonacci
fibonacci was passed 3.
fibonacci was passed 2.
fibonacci was passed 1.
fibonacci was passed 0.
fibonacci was passed 1.
Fibonacci(3) is 3.

Program exited normally.
(gdb)