God will take a

You are born with wings, why actually willing to crawl life, shaped like pests?

"Learning without thought is labor lost, thought without learning is perilous" means:

"Inner thinking" learn to think well of practice should be combined with the "relationship" way of thinking.

Otherwise, direct learning "thinking inside", beginners will practice in trouble, which is indiscriminately.

The only rely on "relationship" way of thinking, it will bring great harm, which is perilous. Author: Jane book links the mind of players: https://www.jianshu.com/p/2940cf732b94 sources

"In-thinking" directly "see" images with a sense of God consciousness yuan, is the need to go through after a period of practice in order to achieve the state. Without practice, not easy to do.

Historical Origins

First, tell us about the historical origins of the library, from the contributors of view, ST is not personal works, but has a strong business background and application support, such as servers, in here you can see the ST had as an Apache module multicore applications release.

Divest its birth was originally developed by Netscape (Netscape) company MSPR (Netscape Portable Runtime library) project out, after a SGI (Silicon Graphic Inc) as well as Yahoo! Inc. (the former is the main) development and maintenance of a separate thread library.

Version, as SourceForge open source project,

Since the release of v1.0 2001 until 2009 v1.9 stable release no further changes.

In terms of platform migration, you can see ST supports a variety of Unix-like platforms, there are also special for rewriting the source code from Win32 Makefile configuration options.

Source example, a web server, proxy dns three kinds of programming and reference examples.

It can be said that the quality of the code should be quite stable and reliable.

card

Coroutine library Language Developers
state threads library 3000 lines of C code Historical Origins
Libtask a Coroutine Library for C and Unix  

Learning Record

A, doc

Read the document 1, a total of 5 times eggplant dish takes 130 minutes

ST understanding is still essentially based on EDSM model , but is intended to replace the traditional asynchronous callback mode for Internet application order born of State Threads

Involve content

State Threads Library Documentation

Key words:

  • ST scheduler (do not know)

the ST scheduler is hidden inside the library and invisible to an application writer.

  • traditional EDSM (do not know)

event-driven state machines (EDSM)

  • virtual processor (do not know)

ST multi-core architecture

  • , ST's threads can be linearly processed I / O events concurrently (understand)
  • execute state event wait queue

  • setjmp / longjmp (understand)

  • I looked at the code and understand the operation of an example

image.png

Read the document 2, the cumulative number eggplant dish 3 took 100 minutes

理解 Libtask: a Coroutine Library for C and Unix 含义

Involve content

Two, code

 1
 2
 3
 4
 5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 
void *_st_idle_thread_start(void *arg) { _st_thread_t *me = _ST_CURRENT_THREAD(); while (_st_active_count > 0) { /* Idle vp till I/O is ready or the smallest timeout expired */ _ST_VP_IDLE(); /* Check sleep queue for expired threads */ _st_vp_check_clock(); me->state = _ST_ST_RUNNABLE; _ST_SWITCH_CONTEXT(me); } /* No more threads */ exit(0); /* NOTREACHED */ return NULL; } /*  * Switch away from the current thread context by saving its state  * and calling the thread scheduler  */ #define _ST_SWITCH_CONTEXT(_thread) \  ST_BEGIN_MACRO \  if (!MD_SETJMP((_thread)->context)) { \  _st_vp_schedule(); \  } \  ST_END_MACRO  /*  * Restore a thread context that was saved by _ST_SWITCH_CONTEXT  * or initialized by _ST_INIT_CONTEXT  */ #define _ST_RESTORE_CONTEXT(_thread) \  ST_BEGIN_MACRO \  _ST_SET_CURRENT_THREAD(_thread); \  MD_LONGJMP((_thread)->context, 1); \  ST_END_MACRO  void _st_vp_schedule(void) { _st_thread_t *thread; if (_ST_RUNQ.next != &_ST_RUNQ) { /* Pull thread off of the run queue */ thread = _ST_THREAD_PTR(_ST_RUNQ.next); _ST_DEL_RUNQ(thread); } else { /* If there are no threads to run, switch to the idle thread */ thread = _st_this_vp.idle_thread; } ST_ASSERT(thread->state == _ST_ST_RUNNABLE); /* Resume the thread */ thread->state = _ST_ST_RUNNING; _ST_RESTORE_CONTEXT(thread); } 

三、talk

  • task compiled into dynamic and static libraries 30 minutes

     1
     2
     3
     4
     5  6  7  8  9 10 11 12 13 14 
    git clone https://github.com/wangcy6/state-threads.git cd state-threads make linux-debug //不同平台 state-threads/obj/ libst.so.1.9 libst.a cd examples/ make linux-debug //不同平台 EXAMPLES = $(OBJDIR)/lookupdns $(OBJDIR)/proxy $(OBJDIR)/server ./lookupdns www.baidu.com www.google.com www.bing.com 

Project Application

No

reference