接上:拖拖拉拉

题外话:

本来预定下周一到的耳机今天(周六)中午就到了,听了一下感觉音效不错,但是也就那么回事,而且卡耳朵卡得有点紧,心想要不要退掉或者卖掉,点回去Amazon一看,已经是正常价140刀了,还是捡了个大便宜呀,可惜用老婆的号买第二个被Amazon cancel了,原因应该是两个账号用的信用卡卡号是一样的...这样理想计划买二卖一泡汤了...不要太贪心嘛

昨晚Larry请我去看电影,极品飞车,3D效果很爽,周五中午公司有披萨,结果一天没出办公室,屁股受不了,晚上本想回家的,下班太累,于是就给自己个借口去放松一下,结果错过老爸发来的Facetime,晚上11点半到家,打回去老爸问我干嘛去了,不想对老爸撒谎,如实说同事请看电影了,“咦也,你看人家”...羞愧难当

老父亲还卧病在床,不能在身边尽孝也抓紧时间做点正事吧!

接上篇,基础问题

threads and processes -- MultiThreading

Threads, of course, allow for multi-threading. A common example of the advantage of multithreading is the fact that you can have a word processor that prints a document using a background thread, but at the same time another thread is running that accepts user input, so that you can type up a new document. If we were dealing with an application that uses only one thread, then the application would only be able to do one thing at a time – so printing and responding to user input at the same time would not be possible in a single threaded application. Each process has it’s own address space, but the threads within the same process share that address space. Threads also share any other resources within that process. This means that it’s very easy to share data amongst threads, but it’s also easy for the threads to step on each other, which can lead to bad things. Multithreaded programs must be carefully programmed to prevent those bad things from happening. Sections of code that modify data structures shared by multiple threads are called critical sections. When a critical section is running in one thread it’s extremely important that no other thread be allowed into that critical section. This is called synchronization, which we wont get into any further over here. But, the point is that multithreading requires careful programming. Also, context switching between threads is generally less expensive than in processes. And finally, the overhead (the cost of communication) between threads is very low relative to processes.

SUMMARY

  1. Threads are easier to create than processes since they don't require a separate address space.

  2. Multithreading requires careful programming since threads share data strucures that should only be modified by one thread at a time. Unlike threads, processes don't share the same address space.

  3. Threads are considered lightweight because they use far less resources than processes.

  4. Processes are independent of each other. Threads, since they share the same address space are interdependent, so caution must be taken so that different threads don't step on each other.
    This is really another way of stating #2 above.

    1. A process can consist of multiple threads.

拖拖拉拉还是开始干正事吧

时间流水账:

7点半下班,7点45到家,没有做饭,随便吃吃蝴蝶酥+牛奶,到现在11点50,有4个小时的时间...看大酒神视频一个多小时,研究对比amazon上面thunderbolt转接线又不知过了多久,期间做了一点点正事就是把老婆要求的在职证明又重新扫描了一遍。 这种时间效率做什么都绝无成功之可能啊!

好了废话不多说,现在做一点有意义的事情。

正事

首先记录一下鹿牛的博客,老早就收藏了,但也没怎么看,以后要多向鹿牛学习。罗大佑的《追梦人》,真是好听。

找工作感觉没什么头绪,感觉算法课要重新学一遍,操作系统也要学,编译原理,设计模式,Spring, Hibernate,统统都要学。。。不过感觉比较实际的还是直接做题,大哥也是这样说。 另外找工群里面BT阿姨整理的资料包很好, 里面收录了一篇没怎么讲技术方面的东西,基本上是一些注意事项,读读也无妨,开卷有益嘛,摘录一点有用的东西:

记不记得俺提到过的experience里要用“吓人”的动词? 给你们一个小列表 (不是我的原创,不记得从哪儿抄来的了)。注意(1)全都是过去时; (2) 没有 studies, investigated, worked on, supported 这些无关痛痒的词。

  1. Accelerated 35. Empowered 69. Motivated
  2. Accomplished 36. Enabled 70. Negotiated
  3. Achieved 37. Encouraged 71. Obtained
  4. Acted 38. Engineered 72. Operated
  5. Adapted 39. Enhanced 73. Orchestrated
  6. Administered 40. Enlisted 74. Organized
  7. Allocated 41. Established 75. Originated
  8. Analyzed 42. Evaluated 76. Overhauled
  9. Approved 43. Examined 77. Oversaw
  10. Assembled 44. Executed 78. Performed
  11. Attained 45. Expedited 79. Pinpointed
  12. Boosted 46. Focused 80. Planned
  13. Budgeted 47. Forecasted 81. Prepared
  14. Built 48. Formulated 82. Prioritized
  15. Calculated 49. Founded 83. Processed
  16. Catalogued 50. Generated 84. Produced
  17. Chaired 51. Guided 85. Reconciled
  18. Coached 52. Harnessed 86. Repaired
  19. Collaborated 53. Identified 87. Researched
  20. Communicated 54. Illustrated 88. Revitalized
  21. Compiled 55. Implemented 89. Selected
  22. Consolidated 56. Improved 90. Solved
  23. Coordinated 57. Increased 91. Spearheaded
  24. Created 58. Initiated 92. Stimulated
  25. Cultivated 59. Instituted 93. Strengthened
  26. Decreased 60. Integrated 94. Succeeded
  27. Demonstrated 61. Introduced 95. Surpassed
  28. Designed 62. Invented 96. Synergized
  29. Developed 63. Launched 97. Troubleshot
  30. Diagnosed 64. Led 98. Uncovered
  31. Directed 65. Maintained 99. Upgraded
  32. Documented 66. Managed 100. Utilized
  33. Doubled 67. Mastered
  34. Educated 68. Mediated

这篇码工求职经验总结就比较靠谱了,非常推荐, 其中关于CS的基础知识一段提到了几个面试中常问的基础问题,今天时间不早了,就挑些软柿子捏捏然后休息吧 ^^.

首先摘录下来这一段:

以前看到有人问说OS/网络层/数据库的东西要不要准备。一般说来问题都取决于简历上的内容,如果简历上没有太多这方面的内容的话,基本上也不怎么会问。不过最基本的概念还是最好能了解,比如 进程和线程的不同,tcp和udp的不同,inner join和outerjoin的不同,等等。这些问题反映了一个人的CS基本功。 比如说简历上要是出现了concurrency的话,那下面这段出自的话里提到的东西应该都要能够了解:

This is just a plug, from me, for you to know about processes, threads and concurrency issues. A lot of interviewers ask about that stuff, and it's pretty fundamental, so you should know it. Know about locks and mutexes and semaphores and monitors and how they work. Know about deadlock and livelock and how to avoid them. Know what resources a processes needs, and a thread needs, and how context switching works, and how it's initiated by the operating system and underlying hardware. Know a little about scheduling. The world is rapidly moving towards multi-core, and you'll be a dinosaur in a real hurry if you don't understand the fundamentals of "modern" (which is to say, "kinda broken") concurrency constructs.

还有就是C++/Java语言的一些基本概念,比如说构造函数、虚函数、接口之类。以及OO 的基本概念。

下面我就总结一下这几个基础问题吧,为了保证充分理解,又能够在面试中说得清楚,中英文的解释都网罗一下。

进程和线程的不同

  • 中文

    进程和线程都是由操作系统所体会的程序运行的基本单元,系统利用该基本单元实现系统对应用的并发性。进程和线程的区别在于: 简而言之,一个程序至少有一个进程,一个进程至少有一个线程. 线程的划分尺度小于进程,使得多线程程序的并发性高。 另外,进程在执行过程中拥有独立的内存单元,而多个线程共享内存,从而极大地提高了程序的运行效率。 线程在执行过程中与进程还是有区别的。每个独立的线程有一个程序运行的入口、顺序执行序列和程序的出口。但是线程不能够独立执行,必须依存在应用程序中,由应用程序提供多个线程执行控制。 从逻辑角度来看,多线程的意义在于一个应用程序中,有多个执行部分可以同时执行。但操作系统并没有将多个线程看做多个独立的应用,来实现进程的调度和管理以及资源分配。这就是进程和线程的重要区别。 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位. 线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序计数器,一组寄存器和栈),但是它可与同属一个进程的其他的线程共享进程所拥有的全部资源. 一个线程可以创建和撤销另一个线程;同一个进程中的多个线程之间可以并发执行. 进程和线程的主要差别在于它们是不同的操作系统资源管理方式。进程有独立的地址空间,一个进程崩溃后,在保护模式下不会对其它进程产生影响,而线程只是一个进程中的不同执行路径。线程有自己的堆栈和局部变量,但线程之间没有单独的地址空间,一个线程死掉就等于整个进程死掉,所以多进程的程序要比多线程的程序健壮,但在进程切换时,耗费资源较大,效率要差一些。但对于一些要求同时进行并且又要共享某些变量的并发操作,只能用线程,不能用进程。如果有兴趣深入的话,我建议你们看看《现代操作系统》或者《操作系统的设计与实现》。对就个问题说得比较清楚。

  • English

    A process is an executing instance of an application. What does that mean? Well, for example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.

Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces. Threads are an operating environment feature, rather than a CPU feature(though the CPU typically has operations that make threads efficient). Erlang uses the term "process" because it does not expose a shared-memory multiprogramming model. Calling them "threads" would imply that they have shared memory.

  • Still English

    A process is an executing instance of an application. What does that mean? Well, for example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.

It’s important to note that a thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Thus, the essential difference between a thread and a process is the work that each one is used to accomplish. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.

Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads. Communication between processes – also known as IPC, or inter-process communication – is quite difficult and resource-intensive.

然后还有Multithreading的内容,已经2点了,就先睡觉吧, 刚刚和爸妈视频了一下,希望爸妈健康,快乐。

PS. 今天Amazon today‘s deal,抢了两个 Harmon Kardon CL Precision耳机,才$70每个,看看老婆如果不要的话就卖掉一个 ^^ 下了很大决心准备买三个呢,结果限购一个。算了,人不能太贪心嘛。