?? omnithread.ps
字號:
(the) e(thr) n(ead) h(for) g(use) g(in) h(debug) n(ging,) pFd 29 w(state) n(\(\)) p Fg(,) p Fd 221 661 a(slee) n(p\(\)) pFg 22 w(and) p Fd 22 w(get_t) n(ime\() n(\)) p Fg(.) pFh 221 953 a(4) 119 b(Per) n(-threa) n(d) 30 b(data) pFg 221 1164 a(omnithr) n(ead) 22 b(suppo) n(rts) g(per) n(-thr) n(ead) f(data,) h(via) i(member) e(functions) f(of) i(the) pFd 21 w(omni) n(_thr) n(ead) p Fg 221 1277 a(object.) 3621390 y(First,) d(you) g(must) h(allocate) h(a) f(key) f(for) g(with) h(the) p Fd 20 w(omni) n(_thre) n(ad::) n(allo) n(cate_) n(key\() n(\)) pFg 221 1502 a(function.) 28 b(Then,) 21 b(any) h(object) g(whose) f(class) h(is) g(derived) f(fr) n(om) p Fd 23 w(omni) n(_thr) n(ead::) n(valu) n(e_t) p Fg 221 1615 a(can) 27 b(be) f(stor) n(e) n(d) g(using) f(the) p Fd 26 w(set) n(_val) n(ue\(\)) p Fg 25 w(function.) 38b(V) -8 b(alues) 25 b(ar) n(e) h(r) n(etrieved) f(or) h(r) n(emoved) 2211728 y(with) p Fd 23 w(get) n(_valu) n(e\(\)) p Fg 21w(and) p Fd 23 w(remo) n(ve_v) n(alue\() n(\)) p Fg 22w(r) n(espectively) -10 b(.) 362 1841 y(When) 23 b(the) g(thr) n(ead) g(exits,) g(all) i(per) n(-thr) n(ead) e(data) h(is) g(delet) n(ed) f(\(hence) h(the) e(base) i(class) g(with) 221 1954 y(virtual) g(dest) n(r) o(uctor\).) 362 2067 y(Note) 17 b(that) i(the) f(per) n(-thr) n(ead) f(data) i(functions) f(ar) n(e) p Fb 19 w(not) pFg 18 w(thr) n(ead) g(safe,) i(so) d(although) i(you) e(can) 2212180 y(access) 29 b(one) e(thr) n(ead's) h(storage) f(fr) n(om) i(another) f(thr) n(ead,) h(ther) n(e) e(is) i(no) f(concurr) n(ency) g(contr) n(ol.) 221 2293 y(Unless) j(you) g(r) n(eall) r(y) h(know) f(what) h(you) f(ar) n(e) i(doing,) g(it) g(is) f(best) f(to) h(only) g(access) g(per) n(-thr) n(ead) 221 2406 y(data) 23 b(fr) n(om) g(the) f(thr) n(ead) g(it) h(is) g(attached) f(to.) p Fh 2212698 a(5) 119 b(Using) 31 b(OMNI) d(threads) h(in) h(your) g(program) pFg 221 2909 a(Obvi) r(ously) 16 b(you) h(need) g(to) g(include) h(the) pFd 16 w(omnit) n(hrea) n(d.h) p Fg 17 w(header) e(\002le) i(in) g(your)f(sour) n(ce) g(code,) 221 3021 y(and) 25 b(link) g(in) h(the) e(omnithr) n(ead) g(libra) r(ry) g(with) h(your) f(execut) n(abl) r(e.)34 b(Because) 23 b(ther) n(e) h(is) h(a) g(single) pFd 221 3134 a(omni) n(threa) n(d.h) p Fg 30 w(for) 32b(all) h(platforms,) h(certain) e(pr) n(epr) n(oces) n(sor) f(de\002nes) f(must) h(be) g(given) h(as) 221 3247 y(compiler) 25b(options) n(.) 33 b(The) 23 b(easiest) g(way) h(to) g(do) f(this) h(is) g(to) g(stud) n(y) g(the) g(make\002les) f(given) h(in) h(the) 2213360 y(examples) i(pr) n(ovided) g(with) g(this) g(distribution.) 42b(If) 27 b(you) g(ar) n(e) g(to) g(include) h(OMNI) f(thr) n(eads) g(in) 221 3473 y(your) 18 b(own) g(development) g(envir) n(onment,) h(thes) n(e) g(ar) n(e) g(the) f(necessary) g(pr) n(epr) n(oce) n(ssor) g(de\002nes) n(:) p 362 3567 3287 4 v 360 3680 4 113 v412 3646 a(Platform) p 1312 3680 V 599 w(Pr) n(epr) n(ocess) n(or) 23b(De\002nes) p 3648 3680 V 362 3683 3287 4 v 362 3700V 360 3813 4 113 v 412 3779 a(Sun) f(Solaris) h(2.x) p1312 3813 V Fd 365 w(-D__) n(suno) n(s__) 54 b(-D_) n(_spa) n(rc__) f(-D__) n(OSVER) n(SION) n(__=5) p 3648 3813 V 360 3926V 1312 3926 V 1363 3892 a(-DSV) n(R4) h(-DUs) n(ePth) n(read) f(-D_R) n(EENT) n(RANT) p 3648 3926 V 362 3929 3287 4 v 360 40424 113 v Fg 412 4008 a(x86) 24 b(Linux) e(2.0) p 13124042 V Fd 418 w(-D__) n(linu) n(x__) 54 b(-D_) n(_i86) n(__) g(-D__) n(OSVE) n(RSION) n(__=2) p 3648 4042 V 360 4155 V Fg 4124121 a(with) 23 b(linuxthr) n(eads) f(0.5) p 1312 4155V Fd 100 w(-D_R) n(EENT) n(RANT) p 3648 4155 V 362 41583287 4 v 360 4271 4 113 v Fg 412 4237 a(Digital) i(Unix) f(3.2) p1312 4271 V Fd 320 w(-D__) n(osf1) n(__) 54 b(-D__) n(alph) n(a__) g(-D_) n(_OSV) n(ERSIO) n(N__=) n(3) p 3648 4271 V 3604384 V 1312 4384 V 1363 4350 a(-D_R) n(EENT) n(RANT) p3648 4384 V 362 4387 3287 4 v 360 4500 4 113 v Fg 4124466 a(W) -5 b(indows) 22 b(NT) p 1312 4500 V Fd 411w(-D__) n(NT__) 53 b(-MD) p 3648 4500 V 362 4503 32874 v Fh 221 4740 a(6) 119 b(Threaded) 29 b(I/O) g(shutdown) h(for) g(Unix) p Fg 221 4951 a(or) -7 b(,) 20 b(how) e(one) g(thr) n(ead) h(shou) n(ld) h(tell) f(another) f(thr) n(ead) g(to) h(shut) f(down) g(when) g(it) h(might) g(be) g(doing) 221 5064 y(a) k(blocking) g(cal) r(l) g(on) f(a) h(socket) n(.) p Fb 362 5177 a(If) h(you) e(are) i(using) e(omniOR) n(B,) h(you) e(don') n(t) i(need) g(to) g(worry) f(about) g(all) i(this,) f(since) h(om-) 221 5290 y(niORB) i(does) h(it)h(for) f(you) n(.) p Fg 41 w(This) g(section) f(is) h(only) g(r) n(elevant) g(if) h(you) e(ar) n(e) h(using) f(omnithr) n(ead) 2215403 y(in) d(your) f(own) g(socket) n(-based) h(pr) n(ogramming.) k(It)22 b(is) h(also) g(serious) n(ly) g(out) f(of) h(date.) p90 rotate dyy eop%%Page: 5 55 4 bop Fe 63 249 a(6.1) 91 b(r) n(ead\(\)) p Fg 2800w(5) 204 548 y(Unfortunate) n(ly) 35 b(ther) n(e) e(doe) n(sn't) h(seem) f(to) h(be) g(a) h(standar) n(d) e(way) i(of) f(doing) f(this) h(which) 63 661 y(works) 19 b(acr) n(oss) i(all) i(Unix) e(syst) n(ems.)27 b(I) 21 b(have) g(investigated) f(the) h(behaviour) g(of) g(Solaris)h(2.5) g(and) 63 774 y(Digital) k(Unix) g(3.2.) 36 b(On) 26b(Digital) h(Unix) e(everyth) n(ing) h(is) f(\002ne,) g(as) h(the) e(obvious) h(method) f(using) 63 887 y(shutd) n(own\(\)) 32b(seems) f(to) h(work) f(OK.) h(Unfortunately) f(on) h(Solaris) h(shut)n(down) f(can) h(only) f(be) 63 1000 y(used) 25 b(on) h(a) h(connected)e(socke) n(t,) i(so) f(we) g(need) f(devious) h(means) g(to) g(get) f(ar) n(ound) h(this) g(lim) r(ita-) 63 1112 y(tion.) h(The) 22b(details) g(ar) n(e) h(summarised) g(below:) p Fc 631429 a(6.1) 99 b(read\(\)) p Fg 63 1627 a(Thr) n(ead) 28b(A) h(is) g(in) h(a) g(loop,) g(doing) p Fd 28 w(rea) n(d\(soc) n(k\))p Fg(,) g(pr) n(ocess) n(ing) f(the) g(data,) h(then) f(going) f(back)63 1739 y(into) 22 b(the) g(r) n(ead.) 204 1862 y(Thr) n(ead) 30b(B) h(comes) f(along) h(and) g(wants) f(to) g(shut) g(it) h(down) f(\227) h(it) g(can't) g(cancel) h(thr) n(ead) f(A) 631975 y(since) 21 b(\(i\)) h(working) e(out) g(how) g(to) h(clean) h(up)e(accor) n(ding) i(to) e(wher) n(e) g(A) h(is) g(in) h(its) f(loop) f(is) h(a) h(night-) 63 2088 y(mar) n(e,) h(and) f(\(ii\)) i(this) f(isn't) f(ava) r(ilabl) r(e) g(in) h(omnithr) n(ead) f(anyway) -10b(.) 204 2211 y(On) 23 b(Solaris) g(2.5) g(and) g(Digital) h(Unix) f(3.2) g(the) f(following) h(strate) n(gy) f(works:) 2042334 y(Thr) n(ead) g(B) g(does) p Fd 21 w(shut) n(down\() n(sock) n(,2\)) p Fg(.) 204 2457 y(At) g(this) g(point) h(thr) n(ead) f(A) g(is)h(either) f(blocked) g(inside) p Fd 23 w(rea) n(d\(so) n(ck\)) pFg(,) g(or) g(is) h(elsewhe) n(r) n(e) g(in) 63 2570y(the) 18 b(loop.) 26 b(If) 18 b(the) g(former) h(then) f(r) n(ead) h(will) h(r) n(eturn) e(0,) i(indicating) f(that) g(the) f(socke) n(t) h(is) g(closed.) 26 b(If) 63 2683 y(the) 21 b(latter) h(then) f(eventually) h(thr) n(ead) g(A) g(will) i(call) p Fd24 w(rea) n(d\(so) n(ck\)) p Fg 21 w(and) f(then) e(this) h(will) h(r) n(eturn) 63 2796 y(0.) 28 b(Thr) n(ead) 22 b(A) h(should) pFd 21 w(clos) n(e\(soc) n(k\)) p Fg(,) f(do) g(any) g(other) g(tidying)f(up,) h(and) h(exit.) 204 2919 y(If) 34 b(ther) n(e) g(is) h(another) f(point) g(in) h(the) e(loop) i(that) f(thr) n(ead) g(A) h(can) g(block)g(then) f(obviously) 63 3032 y(thr) n(ead) 19 b(B) h(needs) f(to) h(be)g(awar) n(e) h(of) f(this) g(and) g(be) h(able) g(to) e(wake) h(it) h(up) f(in) g(the) g(appr) n(opriate) g(way) 63 3145 y(fr) n(om) j(that)f(point.) p Fc 63 3462 a(6.2) 99 b(accept\(\)) p Fg 633659 a(Again) 25 b(thr) n(ead) g(A) h(is) f(in) h(a) g(loop,) g(this) f(time) h(doing) e(an) i(acc) r(ept) e(on) h(listenSock,) g(dealing) h(with) 63 3772 y(a) d(new) f(connection) g(and) h(going) e(back) j(into) e(accept.) 28 b(Thr) n(ead) 22 b(B) g(wants) h(to) f(cancel) h(it.) 204 3895 y(On) g(Digital) h(Unix) f(3.2) g(the) f(strateg) n(y) g(is) h(identical) h(to) e(that) g(for) h(r) n(ead:) 2044018 y(Thr) n(ead) 39 b(B) g(does) p Fd 38 w(shut) n(down) n(\(list) n(enSo) n(ck,2) n(\)) p Fg(.) 79 b(Wher) n(ever) 38 b(thr) n(ead) h(A) h(is) f(in) h(the) 63 4131 y(loop,) i(eventually) c(it) h(will) h(r) n(eturn) p Fd 38 w(ECONN) n(ABOR) n(TED) p Fg 38 w(fr) n(om) f(the) f(accept) h(call) r(.) 76 b(It) 39 b(shou) n(ld) p Fd63 4244 a(clo) n(se\(l) n(isten) n(Sock) n(\)) p Fg(,) 22b(tidy) g(up) g(as) h(necessary) e(and) i(exit.) 2044367 y(On) 30 b(Solaris) f(2.5) i(thr) n(ead) e(B) g(can't) h(do) pFd 29 w(shu) n(tdow) n(n\(lis) n(tenS) n(ock,2) n(\)) pFg 29 w(\227) g(this) f(r) n(eturns) p Fd 63 4480 a(ENO) n(TCON) n(N) pFg(.) 22 b(Instead) f(the) h(following) h(strateg) n(y) g(can) g(be) g(used) n(:) 204 4603 y(First) 35 b(thr) n(ead) h(B) g(set) n(s) g(some)f(sort) g(of) h("shutdo) n(wn) g(\003ag") g(associated) g(with) g(listenSock.) 63 4716 y(Then) 31 b(it) h(does) p Fd 30w(gets) n(ocka) n(ddr\(l) n(iste) n(nSock) n(\)) p Fg32 w(to) f(\002nd) g(out) g(which) i(port) e(listenSock) f(is) 634828 y(on) 18 b(\(or) h(knows) e(alr) n(eady\),) j(sets) d(up) h(a) h(socket) e(dummySock,) i(doe) n(s) p Fd 19 w(con) n(nect) n(\(dumm) n(ySoc) n(k,) 63 4941 y(thi) n(s) 54 b(host,) f(por) n(t\)) pFg 22 w(and) 23 b(\002nally) g(does) p Fd 21 w(clos) n(e\(dum) n(mySo) n(ck\)) p Fg(.) 204 5064 y(Wher) n(ever) 16 b(thr) n(ead) h(A) g(is) g(in) h(the) e(loop,) h(eventually) g(it) h(will) g(call) pFd 19 w(acce) n(pt\(li) n(sten) n(Sock) n(\)) p Fg(.) 635177 y(This) 35 b(will) j(r) n(eturn) d(successfully) g(with) h(a) h(new) e(socket,) j(say) e(connSock.) 67 b(Thr) n(ead) 36b(A) f(then) 63 5290 y(checks) 20 b(to) h(see) f(if) i(the) f("shutd) n(own) g(\003ag") h(is) f(set.) 26 b(If) c(not,) e(then) h(it's) g(a) h(normal) g(connection.) 27 b(If) 21 b(it) 63 5403 y(is) h(set,) g(then)f(thr) n(ead) h(A) h(closes) f(listenSock) f(and) i(connSock,) e(tidies) h(up) g(and) h(exits.) p 90 rotate dyy eop%%Page: 6 66 5 bop Fg 221 249 a(6) p Fe 1367 w(6) 91 b(THRE) n(ADED) 23b(I/O) g(SHUTDOWN) f(FOR) g(UNIX) p Fc 221 548 a(6.3) 99b(write\(\)) p Fg 221 768 a(Thr) n(ead) 19 b(A) f(may) h(be) g(blocked)f(in) i(write,) f(or) f(about) h(to) f(go) g(in) h(to) g(a) g(poten) n(tiall) r(y-blocking) g(write.) 221 881 y(Thr) n(ead) j(B) h(wants) f(to) g(shut) f(it) i(down.) 362 1016 y(On) g(Solaris) g(2.5:) 3621150 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23 w(shu) n(tdown) n(\(soc) n(k,2\)) p Fg -2 w(.) 362 1285 y(If) c(thr) n(ead) f(A) h(is) g(alr) n(eady) g(in) p Fd 20 w(wri) n(te\(s) n(ock\)) p Fg 17w(then) f(it) h(will) i(r) n(eturn) d(with) p Fd 18 w(ENXIO) pFg -2 w(.) h(If) g(thr) n(ead) 221 1398 y(A) k(calls) h(write) e(after)g(thr) n(ead) g(B) h(calls) h(shut) n(down) e(this) g(will) i(r) n(eturn) p Fd 22 w(EIO) p Fg(.) 362 1532 y(On) f(Digital) h(Unix) f(3.2:) 362 1666 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23w(shu) n(tdown) n(\(soc) n(k,2\)) p Fg -2 w(.) 362 1801y(If) h(thr) n(ead) f(A) g(is) h(alr) n(eady) g(in) pFd 24 w(writ) n(e\(so) n(ck\)) p Fg 23 w(then) e(it) i(will) h(r) n(eturn) e(the) f(number) i(of) f(bytes) 221 1914 y(written) 31b(befor) n(e) h(it) g(became) g(blocked.) 55 b(A) 32b(subseq) n(uent) f(cal) r(l) h(to) f(write) h(will) h(then) e(gene) n(rate) p Fd 221 2027 a(SIGP) n(IPE) p Fg 22 w(\(or) pFd 22 w(EPIP) n(E) p Fg 23 w(will) 24 b(be) e(r) n(eturned) f(if) pFd 24 w(SIG) n(PIPE) p Fg 21 w(is) i(ignor) n(ed) e(by) i(the) f(thr) n(ead\).) p Fc 221 2413 a(6.4) 99 b(connect\(\)) p Fg221 2634 a(Thr) n(ead) 30 b(A) f(may) h(be) g(blocked) f(in) i(connect,) g(or) e(about) h(to) f(go) g(in) i(to) e(a) h(poten) n(tiall) r(y-blocking) 221 2747 y(connect.) d(Thr) n(ead) c(B) f(wants) g(to) g(shut) g(it) g(down.) 362 2881 y(On) h(Digital) h(Unix) f(3.2:)362 3016 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23 w(shu) n(tdown) n(\(soc) n(k,2\)) p Fg -2 w(.) 362 3150 y(If) j(thr) n(ead) f(A) g(is) h(alr) n(eady) g(in) p Fd 26 w(conn) n(ect\() n(sock) n(\)) pFg 26 w(then) e(it) i(will) h(r) n(eturn) e(a) h(successful) f(con-) 2213263 y(nection.) 54 b(Subsequ) n(ent) 31 b(r) n(eading) g(or) g(writing) g(will) i(show) d(that) i(the) e(socket) g(has) h(been) g(shut) 221 3376 y(down) 22 b(\(i.e.) 28 b(r) n(ead) 23b(r) n(eturns) e(0,) i(write) f(generate) n(s) p Fd 23w(SIG) n(PIPE) p Fg 21 w(or) g(r) n(eturns) p Fd 22 w(EPI) n(PE) pFg(\).) g(If) h(thr) n(ead) f(A) 221 3489 y(call) r(s) g(connect) g(after) h(thr) n(ead) f(B) g(call) r(s) g(shutdo) n(wn) h(this) f(will)i(r) n(eturn) p Fd 22 w(EIN) n(VAL) p Fg(.) 362 3623y(On) f(Solaris) g(2.5:) 362 3758 y(Ther) n(e) 35 b(is) h(no) f(way) g(to) g(wake) g(up) g(a) h(thr) n(ead) f(which) h(is) g(blocked) f(in) h(connect.) 66 b(Inst) n(ead) 221 3871 y(Solaris) 33 b(for) n(ces) g(us)f(thr) n(ough) g(a) i(ridiculous) f(pr) n(oced) n(ur) n(e) g(whichever)g(way) g(we) f(try) g(it.) 59 b(One) 221 3984 y(way) 23b(is) f(this:) 362 4118 y(First) d(thr) n(ead) h(A) g(cr) n(eates) f(a)h(pipe) g(in) g(addition) g(to) f(the) g(socket) n(.) 27b(Instead) 19 b(of) h(shut) n(ting) g(down) 221 4231y(the) i(socket) n(,) h(thr) n(ead) f(B) g(simply) h(writes) e(a) i(byte) f(to) g(the) g(pipe.) 362 4365 y(Thr) n(ead) 17b(A) g(meanwhile) h(set) n(s) f(the) g(socke) n(t) g(to) g(non-blocking) g(mode) f(using) p Fd 17 w(fcn) n(tl\(s) n(ock,) 2214478 y(F_SE) n(TFL,) 53 b(O_NO) n(NBLO) n(CK\)) p Fg(.) 26b(Then) h(it) g(cal) r(ls) g(connect) g(on) g(the) f(socket) g(\227) h(this) g(will) i(r) n(eturn) p Fd 221 4591 a(EINP) n(ROGRE) n(SS) pFg(.) k(Then) h(it) h(must) e(cal) r(l) p Fd 35 w(sel) n(ect\() n(\)) pFg(,) k(waiting) e(for) f(either) g(sock) g(to) f(become) 2214704 y(writable) 39 b(or) f(for) h(the) e(pipe) h(to) g(become) g(r) n(eadable.) 75 b(If) 39 b(select) e(r) n(eturns) g(that) i(just) e(sock)h(is) 221 4817 y(writable) 30 b(then) f(the) g(connection) g(has) h(succeede) n(d.) 49 b(It) 29 b(then) g(need) n(s) h(to) f(set) f(the) h(socket) f(back) 221 4930 y(to) i(blocking) h(mode) f(using) pFd 30 w(fcnt) n(l\(so) n(ck,) 54 b(F_S) n(ETFL) n(,) h(0\)) pFg(.) c(If) 31 b(instead) e(select) h(r) n(eturns) 2215043 y(that) 23 b(the) e(pipe) h(is) h(r) n(eadable,) g(thr) n(ead) f(A) h(closes) e(the) h(socket) n(,) h(tidies) f(up) g(and) h(exits.) 3625177 y(An) g(alternative) h(method) e(is) i(similar) h(but) e(to) g(use) f(polling) i(instead) e(of) i(the) e(pipe.) 29b(Thr) n(ead) 221 5290 y(B) 24 b(justs) e(sets) g(a) j(\003ag) f(and) g(thr) n(ead) f(A) h(calls) h(select) e(with) g(a) i(timeout,) e(period)n(ica) r(lly) h(waking) f(up) 221 5403 y(to) f(see) g(if) h(the) f(\003ag) h(has) f(been) g(set.) p 90 rotate dyy eop%%Page: 7 77 6 bop Fe 63 249 a(REF) n(ERENCES) p Fg 2660 w(7) pFh 63 548 a(Refere) n(nces) p Fg 63 759 a([POSIX94]) pFa 46 w(Portable) 29 b(Operat) r(ing) f(System) g(Interface) h(\(POSIX\)) e(Thr) n(ea) r(ds) h(Extension) p Fg(,) h(P1003) r(.1c) 245872 y(Draft) 23 b(10,) g(IEEE,) e(Septe) n(mber) i(1994) r(.) 631059 y([Birr) n(ell89]) p Fa 47 w(An) 28 b(Intr) n(od) r(uction) g(to) h(Pr) n(ogr) r(amming) g(with) g(Thr) n(ead) r(s) p Fg(,) h(Rese) n(ar) n(ch) g(Repo) n(rt) e(35,) j(DEC) 245 1172 y(Syst) n(ems) 22b(Resear) n(ch) g(Center) -7 b(,) 22 b(Palo) h(Alto,) f(CA,) h(January)g(1989) r(.) p 90 rotate dyy eop%%Trailerenduserdict /end-hook known{end-hook}if%%EOF
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -