?? omnithread.ps
字號:
100 100 120 3[ 47 18[ 60 60 60 60 60 60 1[ 35 1[ 40 45[{TeXBase1Encoding ReEncodeFont} 38 119.552 /Palatino-Boldrf /Fi 137[ 50 2[ 39 9[ 28 3[ 39 50 17[ 66 82[{TeXBase1Encoding ReEncodeFont} 6 99.6264 /Palatino-Italicrf /Fj 137[ 56 1[ 32 42 39 2[ 54 58 88 3[ 29 58 55 1[ 4861 44 55 50 12[ 61 1[ 67 3[ 83 1[ 61 8[ 71 1[ 78 14[ 5050 50 9[ 78 38[{ TeXBase1Encoding ReEncodeFont} 25 99.6264/Palatino-Roman rf /Fk 139[ 47 61 57 2[ 78 83 4[ 42 832[ 69 88 64 79 72 12[ 88 4[ 113 119 136 3[ 48 7[ 11265[{ TeXBase1Encoding ReEncodeFont} 18 143.462 /Palatino-Romanrf end%%EndProlog%%BeginSetup%%Feature: *Resolution 600dpiTeXDict begin%%PaperSize: A4%%EndSetup%%Page: 1 11 0 bop Fk 728 918 a(The) 36 b(OMNI) g(Thr) m(ead) f(Abstracti) n(on) pFj 1293 1176 a(T) -9 b(ristan) 26 b(Richar) n(dson) 10221293 y(A) -7 b(T&T) 24 b(Laboratories) i(Cambridge) pFi 1192 1504 a(Revised) p Fj 24 w(November) f(2001) pFh 63 1961 a(1) 119 b(Introduction) p Fg 63 2183 a(The) 20b(OMNI) h(thr) n(ead) g(abstraction) g(is) h(des) n(igned) f(to) f(pr) n(ovide) h(a) h(common) f(set) f(of) h(thr) n(ead) g(oper) n(-) 632296 y(ations) h(for) g(use) g(in) h(pr) n(ograms) f(written) f(in) i(C++.) 29 b(Pr) n(ograms) 22 b(written) g(using) f(the) h(abstraction)63 2409 y(should) 30 b(be) g(much) i(easier) e(to) g(port) g(betwee) n(n) h(dif) n(fer) n(ent) g(ar) n(chi) r(tectur) l(es) g(with) g(dif) n(fer) n(ent) f(un-) 63 2522 y(derlying) 21 b(thr) n(eads) h(primitives.) 204 2640 y(The) 17 b(pr) n(ogramming) h(interface) g(is) f(designed) f(to) h(be) h(similar) h(to) e(the) g(C) i(language) e(interface) 63 2753 y(to) k(POSIX) h(thr) n(eads) f(\(IEEE) g(draft) h(standar) n(d) f(100) r(3.1c) i(\227) f(pr) n(eviously) g(1003) r(.4a,)g(often) g(known) 63 2866 y(as) g(\223pthr) n(eads\224) h([POSIX94]\).)204 2985 y(Much) 18 b(of) f(the) g(abstraction) i(consists) d(of) i(simple) g(C++) g(object) g(wrappers) e(ar) n(ound) h(pthr) n(ead) 633098 y(calls.) 28 b(Howe) n(ver) 20 b(for) f(some) f(featur) n(es) g(such) h(as) h(thr) n(ead-spe) n(ci\002c) h(data,) f(a) f(better) f(interface) i(can) 63 3211 y(be) i(of) n(fer) n(ed) g(because) h(of) f(the) g(use) g(of) g(C++.) 204 3329 y(Some) 28 b(of) h(the) f(mor) n(e)h(complex) f(featur) n(es) g(of) h(pthr) n(eads) f(ar) n(e) h(not) f(suppo) n(rted) g(because) h(of) 63 3442 y(the) e(dif) n(\002culty) i(of) f(ensuring) g(the) f(same) h(featur) n(es) g(can) h(be) f(of) n(fer) n(ed) g(on) g(top) g(of) g(other) f(thr) n(ead) 633555 y(sys) n(tems.) f(Such) 17 b(featur) n(es) g(include) h(thr) n(ead) f(cancell) r(ation) g(and) h(complex) g(schedu) n(ling) h(contr) n(ol) 63 3668 y(\(thoug) n(h) k(simple) g(thr) n(ead) f(priorities) g(ar) n(e) h(supp) n(orted\).) 204 3787 y(The) i(abstraction) h(layer) h(is) f(curr) n(ently) f(implemented) g(for) h(the) f(following) i(ar) n(chitectur) n(es) 63 3900 y(/) 22 b(thr) n(ead) h(sys) n(tems:) pFf 199 4141 a(\017) p Fg 46 w(Solaris) g(2.x) g(using) f(pthr) n(eads) f(draft) h(10) p Ff 199 4351 a(\017) p Fg 46 w(Solaris) h(2.x) g(using) f(solaris) g(thr) n(eads) g(\(but) h(pthr) n(eads) e(version) h(is) h(now) f(standar) n(d\)) p Ff 199 4561 a(\017) p Fg 46w(Alpha) h(OSF1) g(using) f(pthr) n(eads) f(draft) i(4) pFf 199 4772 a(\017) p Fg 46 w(W) -5 b(indows) 21 b(NT) h(using) g(NT) g(thr) n(eads) p Ff 199 4982 a(\017) p Fg 46 w(Linux) g(2.x) h(using) f(Linuxthr) n(ead) g(0.5) h(\(which) h(is) e(based) g(on) h(pthr) n(eads) e(draft) i(10\)) p Ff 199 5193 a(\017) p Fg 46w(Linux) f(2.x) h(using) f(MIT) g(pthr) n(eads) f(\(which) j(is) f(based) f(on) g(draft) h(8\)) p Ff 199 5403 a(\017) pFg 46 w(A) -7 b(TMos) 22 b(using) g(pthr) n(eads) f(draft) h(6) i(\(but) e(not) g(V) -5 b(irata) 23 b(A) -7 b(TMos\)) 16845652 y(1) p 90 rotate dyy eop%%Page: 2 22 1 bop Fg 221 249 a(2) p Fe 1797 w(2) 91 b(SYNCHRONI) n(SA) -7b(TION) 22 b(OBJECTS) p Fg 362 548 a(See) h(the) p Fd22 w(omni) n(thre) n(ad.h) p Fg 22 w(header) f(\002le) i(for) f(full) i(det) n(ail) r(s) e(of) g(the) g(API.) f(The) h(des) n(criptions) 221661 y(below) 35 b(assume) g(you) g(have) h(some) e(pr) n(evious) h(knowled) n(ge) g(of) h(thr) n(eads) n(,) j(mutexes) n(,) g(condi-) 221774 y(tion) f(varia) r(bles) g(and) g(semaphor) n(es) n(.) 75b(Also) 38 b(r) n(efer) f(to) h(other) f(document) n(ation) i(\([Birr) n(ell89) r(],) 221 887 y([POSIX94) q(]\)) 22 b(for) g(further) f(explanation) i(of) f(thes) n(e) g(ideas) g(\(particularly) h(condition) f(variab) r(les,) 221 1000 y(the) g(use) g(of) g(which) h(may) g(not) f(be) h(particularly) h(intuitive) f(when) f(\002rst) f(encounter) n(ed) n(\).) p Fh 221 1299 a(2) 119 b(Synchronisation) 31b(objects) p Fg 221 1510 a(Synchr) n(onisation) 26 b(objects) h(ar) n(e) g(used) e(to) h(synchr) n(onise) g(thr) n(eads) g(within) h(the) f(same) h(pr) n(ocess) n(.) 221 1623 y(Ther) n(e) j(is) i(no) f(inter) n(-pr) n(ocess) f(synchr) n(onisation) g(pr) n(ovided.) 53b(The) 30 b(synchr) n(onisation) h(objects) 221 1735y(pr) n(ovided) 22 b(ar) n(e) h(mutexes) n(,) g(condition) f(variab) r(les) g(and) h(counting) f(semaphor) n(e) n(s.) p Fc221 1991 a(2.1) 99 b(Mutex) p Fg 221 2168 a(An) 26 b(object) g(of) h(typ) n(e) p Fd 26 w(omni) n(_mute) n(x) p Fg 26 w(is) g(use) n(d) f(for) h(mutual) f(exclusion.) 39 b(It) 26 b(pr) n(ovides) f(two) g(op-)221 2281 y(erations,) p Fd 37 w(lock\() n(\)) p Fg 35w(and) p Fd 35 w(unloc) n(k\(\)) p Fg(.) 64 b(The) 35b(alternative) h(names) p Fd 35 w(acq) n(uire\() n(\)) pFg 35 w(and) p Fd 35 w(re-) 221 2393 y(leas) n(e\(\)) pFg 19 w(can) 21 b(be) f(used) f(if) i(pr) n(eferr) n(ed) n(.) 27b(Behaviour) 20 b(is) g(unde\002ne) n(d) g(when) f(a) i(thr) n(ead) f(attempt) n(s) 221 2506 y(to) 30 b(lock) h(the) e(same) i(mutex) f(again) h(or) f(when) g(a) h(mutex) f(is) h(locked) e(by) i(one) e(thr)n(ead) h(and) h(un-) 221 2619 y(locked) 22 b(by) h(a) g(dif) n(fer) n(ent) f(thr) n(ead.) p Fc 221 2874 a(2.2) 99 b(Condition) 26b(V) -11 b(ariable) p Fg 221 3051 a(A) 28 b(condition) f(varia) r(ble) h(is) g(r) n(epr) n(ese) n(nted) f(by) h(an) p Fd 28 w(omn) n(i_con) n(diti) n(on) p Fg 27 w(and) g(is) g(used) e(for) i(sig-) 2213164 y(nalli) r(ng) 20 b(betwee) n(n) g(thr) n(eads.) 26b(A) 21 b(call) h(to) p Fd 19 w(wait\() n(\)) p Fg 20w(causes) e(a) h(thr) n(ead) e(to) h(wait) h(on) f(the) f(condition) 2213277 y(varia) r(ble.) 45 b(A) 28 b(call) i(to) p Fd 27w(sign) n(al\(\)) p Fg 27 w(wakes) d(up) h(at) g(least) g(one) f(thr) n(ead) h(if) h(any) f(ar) n(e) g(waiting.) 45 b(A) 2213390 y(call) 25 b(to) p Fd 22 w(bro) n(adca) n(st\(\)) pFg 21 w(wakes) d(up) g(all) i(thr) n(eads) e(waiting) h(on) f(the) g(condition) g(varia) r(ble.) 362 3503 y(When) 30 b(constr) o(ucte) n(d,) i(a) e(pointer) f(to) h(an) p Fd 30 w(omni) n(_mute) n(x) pFg 30 w(must) f(be) h(given.) 50 b(A) 30 b(condition) 2213616 y(varia) r(ble) p Fd 33 w(wait\() n(\)) p Fg 33w(has) j(an) h(implic) r(it) f(mutex) p Fd 33 w(unlo) n(ck\(\)) pFg 32 w(and) p Fd 33 w(lock) n(\(\)) p Fg 33 w(ar) n(ound) g(it.) 60b(The) 221 3729 y(link) 30 b(between) f(condition) g(varia) r(ble) h(and) g(mutex) f(lasts) g(for) h(the) f(lifetime) i(of) e(the) g(condition) 221 3842 y(varia) r(ble) c(\(unlike) h(pthr) n(eads) e(wher) n(e) g(the) h(link) h(is) f(only) g(for) g(the) g(duration) f(of) i(the) e(wait\).) 37 b(The) 221 3955 y(same) 23b(mutex) f(may) h(be) f(used) f(with) i(several) f(condition) h(variab)r(les.) 362 4068 y(A) c(wait) g(with) g(a) g(timeout) f(can) i(be) e(achieved) h(by) g(call) r(ing) p Fd 19 w(tim) n(ed_w) n(ait\(\)) pFg -2 w(.) 27 b(This) 18 b(is) h(given) 221 4181 y(an) 27b(absolute) e(time) h(to) f(wait) h(until.) 38 b(The) 26b(r) n(outine) p Fd 25 w(omn) n(i_thr) n(ead:) n(:get_) n(time) n(\(\))p Fg 25 w(can) h(be) 221 4293 y(used) 21 b(to) h(turn) g(a) h(r) n(elativ) r(e) f(time) g(into) h(an) g(absolute) f(time.) pFd 28 w(tim) n(ed_wa) n(it\(\)) p Fg 21 w(r) n(eturns) pFd 21 w(true) p Fg 21 w(if) 221 4406 y(the) 27 b(condition) h(was) g(signalled,) p Fd 29 w(false) p Fg 26 w(if) h(the) f(time) g(expir) n(ed) f(befor) n(e) g(the) h(condition) f(vari) r(-) 2214519 y(able) d(was) e(signalled.) p Fc 221 4774 a(2.3) 99b(Counting) 26 b(semaphores) p Fg 221 4951 a(An) p Fd21 w(omn) n(i_sem) n(apho) n(re) p Fg 20 w(is) 21 b(a) h(counting) e(semaphor) n(e) n(.) 28 b(When) 20 b(cr) n(eated) g(it) h(is) g(given) g(an) g(initial) 221 5064 y(unsigned) j(intege) n(r) i(value.) 36b(When) p Fd 25 w(wai) n(t\(\)) p Fg 24 w(is) 26 b(called,) g(the) f(value) h(is) f(decr) n(emente) n(d) g(if) h(non-) 2215177 y(zer) n(o.) 43 b(If) 27 b(the) g(value) h(is) f(zer) n(o) h(then)f(the) f(thr) n(ead) h(blocks) h(instead.) 41 b(When) pFd 27 w(post) n(\(\)) p Fg 27 w(is) 27 b(cal) r(led,) 2215290 y(if) h(any) g(thr) n(eads) e(ar) n(e) i(blocked) f(in) pFd 27 w(wait\() n(\)) p Fg(,) h(exactly) f(one) g(thr) n(ead) g(is) g(woken.) 41 b(If) 27 b(no) g(thr) n(eads) 221 5403 y(wer) n(e) 22b(blocked) g(then) g(the) g(value) h(of) g(the) e(semaphor) n(e) h(is) h(incr) n(emented.) p 90 rotate dyy eop%%Page: 3 33 2 bop Fg 3306 249 a(3) 204 548 y(If) 27 b(a) h(thr) n(ead) e(cal) r(ls) p Fd 27 w(try) n(_wait) n(\(\)) p Fg(,) h(then) g(the) f(thr) n(ead) g(won't) h(block) h(if) f(the) g(semaphor) n(e's) 63661 y(value) c(is) g(0,) g(r) n(eturning) p Fd 21 w(false) pFg 21 w(instead.) 204 777 y(Ther) n(e) f(is) g(no) h(way) f(of) h(query) n(ing) g(the) f(value) h(of) g(the) f(semaphor) n(e) n(.) pFh 63 1095 a(3) 119 b(Thread) 29 b(object) p Fg 63 1313a(A) 23 b(thr) n(ead) g(is) h(r) n(epr) n(ese) n(nted) e(by) i(an) pFd 24 w(omni) n(_thr) n(ead) p Fg 23 w(object.) 30 b(Ther) n(e) 23b(ar) n(e) h(br) n(oadly) g(two) e(dif) n(fer) n(-) 631426 y(ent) f(ways) i(in) g(which) g(it) g(can) g(be) g(used) n(.) 2041542 y(The) 28 b(\002rst) g(way) h(is) h(simply) f(to) f(cr) n(eate) h(an) p Fd 30 w(omn) n(i_thr) n(ead) p Fg 28 w(object,) h(giving) g(a) f(particula) r(r) 63 1655 y(function) c(which) h(the) e(thr) n(ead) h(should) f(execute) n(.) 36 b(This) 25 b(is) g(like) g(the) g(POSIX) f(\(or) i(any) f(other) n(\)) h(C) 63 1768 y(language) c(interface.) 2041884 y(The) k(second) f(method) h(of) h(use) e(is) i(to) f(cr) n(eate) h(a) g(new) g(class) g(which) g(inherits) f(fr) n(om) pFd 28 w(omn) n(i_) 63 1997 y(thr) n(ead) p Fg(.) 50 b(In) 31b(this) f(case) g(the) g(thr) n(ead) g(will) i(execute) d(the) pFd 29 w(run\(\)) p Fg 29 w(member) h(function) h(of) f(the) 632109 y(new) 22 b(class.) 29 b(One) 23 b(advantage) g(of) g(this) g(scheme) f(is) h(that) g(thr) n(ead-speci\002c) g(data) g(can) h(be) f(imple-) 63 2222 y(mented) e(simply) h(by) h(having) g(data) g(members)f(of) h(the) f(new) g(class.) 204 2339 y(When) f(constr) o(ucted) g(a) i(thr) n(ead) f(is) g(in) h(the) e("new") h(state) f(and) h(has) g(not) g(actuall) r(y) g(starte) n(d.) 28 b(A) 63 2451 y(call) j(to) pFd 29 w(sta) n(rt\(\)) p Fg 28 w(causes) e(the) g(thr) n(ead) g(to) g(begin) g(executing.) 47 b(A) 29 b(static) h(member) f(function) pFd 63 2564 a(cre) n(ate\() n(\)) p Fg 32 w(is) j(pr) n(ovided) f(to) g(constr) o(uct) g(and) g(start) g(a) i(thr) n(ead) e(in) h(a) g(single)g(call.) 57 b(A) 31 b(thr) n(ead) 63 2677 y(exits) 21b(by) i(call) r(ing) p Fd 22 w(exit\() n(\)) p Fg 22w(or) g(by) f(r) n(eturning) g(fr) n(om) h(the) f(thr) n(ead) g(function.) 204 2793 y(Thr) n(eads) 27 b(can) j(be) e(either) g(detached) f(or) h(undetached) n(.) 46 b(Detached) 28b(thr) n(eads) g(ar) n(e) h(thr) n(eads) 63 2906 y(for) h(which) i(all)g(state) e(will) i(be) f(lost) f(upon) g(exit.) 52 b(Other) 30b(thr) n(eads) g(cannot) h(dete) n(rmine) g(when) 633019 y(a) e(detached) f(thr) n(ead) h(will) h(disappear) -7b(,) 31 b(and) e(ther) n(efor) n(e) f(should) g(not) h(attempt) f(to) g(access) h(the) 63 3132 y(thr) n(ead) 23 b(object) g(unless) f(some) h(explicit) h(synchr) n(onisation) f(with) g(the) g(detached) f(thr) n(ead) h(guar) n(-) 63 3245 y(antees) e(that) h(it) h(still) g(exists.)204 3361 y(Undet) n(ached) 33 b(thr) n(eads) f(ar) n(e) i(thr) n(eads) e(for) h(which) g(storage) f(is) h(not) f(r) n(eclai) r(med) g(until) i(an-) 63 3474 y(othe) n(r) g(thr) n(ead) g(waits) g(for) g(its) g(termination) g(by) g(call) r(ing) p Fd 34 w(joi) n(n\(\)) pFg(.) 61 b(An) 34 b(exit) g(value) h(can) g(be) 63 3587y(passe) n(d) 23 b(fr) n(om) g(an) g(undet) n(ached) g(thr) n(ead) f(to) g(the) g(thr) n(ead) g(which) h(joins) g(it.) 2043703 y(Detached) 31 b(/) h(undetached) e(thr) n(eads) h(ar) n(e) i(distinguish) n(ed) f(on) f(cr) n(eation) h(by) g(the) f(type) g(of) 633816 y(function) 24 b(they) e(execute.) 30 b(Undetached) 22b(thr) n(eads) h(execute) g(a) h(function) g(which) g(has) g(a) pFd 25 w(voi) n(d*) p Fg 63 3929 a(r) n(eturn) c(typ) n(e,) h(wher) n(eas) f(detached) f(thr) n(eads) h(execute) f(a) j(function) f(which) g(has) g(a) p Fd 21 w(void) p Fg 19 w(r) n(eturn) 63 4042y(typ) n(e.) 52 b(Unfortunate) n(ly) 31 b(C++) g(member) g(functions) f(ar) n(e) h(not) f(allowed) g(to) g(be) h(distingu) n(ished) 634155 y(simply) 26 b(by) h(their) f(r) n(eturn) g(type) n(.) 40b(Thus) 26 b(in) h(the) f(case) h(of) g(a) g(derived) f(class) h(of) pFd 26 w(omni_) n(thre) n(ad) p Fg 63 4268 a(which) 20b(needs) e(an) j(undet) n(ached) f(thr) n(ead,) g(the) f(member) h(function) g(execute) n(d) g(by) g(the) f(thr) n(ead) g(is) 634380 y(called) p Fd 19 w(run_u) n(ndet) n(ache) n(d\(\)) pFg 18 w(rather) f(than) p Fd 19 w(run\() n(\)) p Fg(,) h(and) g(it) g(is) g(started) e(by) i(calli) r(ng) p Fd 18 w(star) n(t_) 634493 y(und) n(etac) n(hed\(\)) p Fg 21 w(instead) j(of) pFd 22 w(start) n(\(\)) p Fg(.) 204 4610 y(The) i(abstraction) i(curr) n(ently) e(suppo) n(rts) h(thr) n(ee) f(priorities) g(of) h(thr) n(ead,)g(but) g(no) g(guarantee) 63 4722 y(is) 33 b(made) g(of) h(how) f(this)g(will) h(af) n(f) r(ect) f(underlying) f(thr) n(ead) h(scheduling.) 59b(The) 33 b(thr) n(ee) f(priori-) 63 4835 y(ties) 18b(ar) n(e) p Fd 20 w(PRIO) n(RITY) n(_LOW) p Fg(,) pFd 18 w(PRIO) n(RITY) n(_NOR) n(MAL) p Fg 19 w(and) pFd 19 w(PRIO) n(RITY) n(_HIG) n(H) p Fg(.) h(By) g(default) g(all) 634948 y(thr) n(eads) i(r) o(un) i(at) p Fd 23 w(PRIO) n(RITY) n(_NORM) n(AL) p Fg(.) f(A) g(dif) n(fer) n(ent) h(priority) f(can) i(be) e(speci\002ed) g(on) g(thr) n(ead) 63 5061 y(cr) n(eation,) h(or) f(while) h(the) f(thr) n(ead) g(is) h(r) o(unning) g(using) pFd 22 w(set_) n(prio) n(rity\() n(\).) p Fg 28 w(A) g(thr) n(ead's) f(cur) n(-) 63 5174 y(r) n(ent) g(priority) g(is) g(r) n(eturned) f(by) pFd 23 w(pri) n(ority) n(\(\)) p Fg(.) 204 5290 y(Other) d(functions) g(pr) n(ovided) g(ar) n(e) p Fd 19 w(sel) n(f\(\)) p Fg18 w(which) h(r) n(eturns) e(the) h(calli) r(ng) g(thr) n(ead's) pFd 18 w(omn) n(i_) 63 5403 y(thr) n(ead) p Fg 36 w(object,) pFd 40 w(yie) n(ld\(\)) p Fg 35 w(which) 38 b(r) n(eques) n(ts) e(that) h(other) e(thr) n(eads) h(be) h(allowed) g(to) f(r) o(un,) p90 rotate dyy eop%%Page: 4 44 3 bop Fg 221 249 a(4) p Fe 1367 w(6) 91 b(THRE) n(ADED) 23b(I/O) g(SHUTDOWN) f(FOR) g(UNIX) p Fd 221 548 a(id\(\)) pFg 27 w(which) 29 b(r) n(eturns) e(an) i(intege) n(r) g(id) f(for) h
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -