... gian địa chỉ.
Nhờ đó ccluồngc thể sử dụng cc biến toàn c c, chia sẻ cc tài nguyên.
- C ch th cccluồng chia sẻ CPU c ng giống nhƣ c ch th c của cc quá trình.
- Một luồngc ng c những ... kh c
nhau.
2.2.7. Đaluồng
Chƣơng trình Java cung c p giải pháp đaluồng (Multithreading) để th c thi cc
c ng vi c đồng thời. Chúng c ng cung c p giải pháp đồng bộ giữa cc luồng. Đ c tính ... th c hiện luồng
Với Java ta c thể xây dựng cc chƣơng trìnhđa luồng. Một ứng dụng c thể bao
gồm nhiều luồng, mỗi luồng đƣ c gán một c ng vi c cụ thể, chúng đƣ c th c thi đồng
thời với c c...
... quả chạy chương trình thu đư c cũng giống như ví dụ trên.
4.2.2. Độ ưu tiên c a cc luồng
- Ðộ ưu tiên c a ccluồng x c định m c ưu tiên trong vi c phân phối CPU giữa
c cluồng với nhau. Khi c ... mở đư c cổng một c ch tường minh. Thay vào đó cclậptrình viên sẽ dùng thư
viện socket đư c hỗ trợ sẵn bởi cc ngôn ngữ lập trình. Như vậy, cc socket vẫn tồn tại
để kết nối cc ứng dụng c a ... nó sử dụng cc cú
pháp c a C và cc đ c trưng hướng đối tượng c a C+ +.
Vào năm 1991, một nhóm cc kỹ sư c a Sun Microsystems c ý định thiết kế
một ngôn ngữ lậptrình để điều khiển cc thiết bị...
... (luồng main). Trongluồng main:
C thể tạo ccluồng con.
Chương trình phải đảm bảo main là luồng kết th c cuối
c ng.
Khi luồng main ngừng th c thi, chương trình sẽ kết th c
Luồng c ... yield(), luồng đưa cho ccluồng kh c với
c ng quyền ưu tiên c hội sử dụng CPU. Nếu không
c luồng nào kh c cùng quyền ưu tiên tồn tại, luồng
tiếp t c th c hiện
Khi gọi sleep(), luồng ngủ trong ... Nguyễn Đ c Hiển – Bài giảng Lậptrình Java
2
Chương 6
Lập trìnhđa luồng
(Multi-Thread Programming)
Nguyễn Đ c Hiển – Bài giảng Lậptrình Java
24
C c vấn đề Producer/Customer
Khi luồng sản...
... Minh
8
8
Delegates
Delegates
delegate
delegate
–
–
C
C
ó
ó
nh
nh
ữ
ữ
ng
ng
c ng
c ng
vi
vi
ệ
ệ
c
c
không
không
x
x
á
á
c
c
đ
đ
ị
ị
nh
nh
l
l
ú
ú
c
c
biên
biên
d
d
ị
ị
ch
ch
,
,
ch
ch
ỉ
ỉ
x
x
á
á
c
c
đ
đ
ị
ị
nh
nh
l
l
ú
ú
c
c
th
th
ự
ự
c
c
thi
thi
.
.
–
–
C
C
á
á
c
c
thu
thu
ậ
ậ
t
t
to
to
á
á
n
n
t
t
ổ
ổ
ng
ng
qu
qu
á
á
t
t
, ... date,
c
c
á
á
c
c
c
c
ấ
ấ
u
u
tr
tr
ú
ú
c
c
,
,
c
c
á
á
c
c
ki
ki
ể
ể
u
u
li
li
ệ
ệ
t
t
kê
kê
–
–
Reference Data Types:
Reference Data Types:
Ch
Ch
ứ
ứ
a
a
m
m
ộ
ộ
t
t
con
con
tr
tr
ỏ
ỏ
tr
tr
ỏ
ỏ
t
t
ớ
ớ
i
i
nơi
nơi
c
c
ấ
ấ
t
t
gi
gi
ữ
ữ
d
d
ữ
ữ
li
li
ệ
ệ
u
u
Bao
Bao
g
g
ồ
ồ
m
m
ki
ki
ể
ể
u
u
string, ...
template
c
c
ủ
ủ
a
a
C+ +.
C+ +.
–
–
Generics
Generics
xu
xu
ấ
ấ
t
t
hi
hi
ệ
ệ
n
n
nh
nh
ằ
ằ
m
m
m
m
ụ
ụ
c
c
đ
đ
í
í
ch
ch
x
x
ử
ử
l
l
í
í
ch
ch
í
í
nh
nh
x
x
á
á
c
c
ki
ki
ể
ể
u
u
c
c
ủ
ủ
a
a
d
d
ữ
ữ
li
li
ệ
ệ
u
u
....
... bộ kiểu CSyncObject, là lớp c sở ảo cung c p c chế
đồng bộ giữa cc luồng. Cc lớp kề thừa gồm CEvent, CMutex,
CCriticalSection, CSemaphore.
9
8.5. Đồng bộ ccluồng
C c bư c th c hiện ... luồng.
Mỗi chương trình khi chạy luôn c một luồng ứng với th c hiện hàm chính
c a chương trình (WinMain), ccluồng kh c đư c tạo ra từ luồng này.
luồng 3
luồng 1 luồng 4
luồng chính (main thread)
luồng ... lậptrìnhđa luồng
Khai th c tính đa nhiệm, một chương trìnhc thể lậptrình th c hiện nhiều
phần vi c đồng thời. Gọi là lậptrìnhđaluồng (thread), c thể gọi đa tuyến.
Luồng là quá trình...
... c chứa sẵn cc
collection framework trong namespace
System.Collections.Generic .
Generic c thể tạo đư ccc interface,
class, method, event và delegates.
Generic Collection trong C#
C c ... Collection trong C#
C c cấu tr c tổng quát c n lại như Collection,
List thao t c cũng tương tự như c u tr c từ
điển tổng quát.
C c ví dụ c thể về cc trường hợp này c thể
xem thêm trong MSDN
...
IDictionary, IDictionaryEnumerator và cc
generic tương đương c a chúng.
Nội dung
Khái niệm, khai báo, c ch sử dụng lậptrình
tổng quát (Generic).
Lập trình tổng quát lớp, c u tr c và c c...
... main:
C thể tạo ccluồng con.
Chương trình phải đảm bảo main là luồng kết th c cuối
c ng.
Khi luồng main ngừng th c thi, chương trình sẽ kết th c
Luồng c thể đư c tạo ra bằng 2 c ch:
Tạo ...
một luồng quyền ưu tiên thấp đang đư c chạy, luồng
quyền c quyền ưu tiên cao hơn c thể giành quyền
sử dụng CPU c a nó.
Nếu ccluồngcc ng quyền ưu tiên đang chờ đợi
để th c hiện, một luồng ... thiệu
Một luồng (thread) là gì?
Một “dòng điều khiển " trong chương trình
C c chương trình thường chỉ c một dòng điều khiển.
Với cc luồng, bạn c thể c nhiều dòng điều khiển th c
hiện c ng...
... by scan con-
verting the basic geometric-structure specifications into pixel patterns. Typically,
graphics programming packages provide functions to describe a scene in terms
of these basic ... other conic sections, quadric surfaces,
spline curves and surfaces, polygon color areas, and character strings. We begin
our discussion of picture-generation procedures by examining device-level ...
Voice Systems
Speech
recognizers
are
used
in some graphics workstations as input devices to
accept voice commands The voice-system input can
be
used
to
initiate graphics
REFERENCES...
... general curve contour, then fitting.the selected points
with a polynomial. One way to accomplish the curve fitting is to construct a
cubic polynomial curve section between each pair of specified ... tint n, wcPt2 pts)
Draw a connected sequence of
n-1
line segments, specified in
pts .
pCircle (wcPt2 center, float r)
Draw a circle of radius
r
at
center.
ppillarea (int n, wcPt2
pts) ...
a
curve,
ci\rcles
(or
markers), and text.
?hftesy
of
Wolfmrn
hrch,
Inc.,
The
Mah
of
Malhtica.J
Additional primitives available in graphics packages include cell arrays,
character...
... With the
direct
storage scheme, when-
ever a particular color code is specified in an application program, the corre-
sponding binary value is placed in the frame buffer for each-component pixel ... fill color with the two back-
ground colors to obtain the new pixel color. With three background colors and
one foreground color, or with two background and two foreground colors, we
nccd all ...
solved. This occurs when the color val-
ucs are all very similar or when they are all proportional to each other.
CHARACTER ATTRIBUTES
The appearance of displayed characters is controlled by...
... lines arc then processed through the intersection calculations,
which must solve simultaneous circle-line equations
Splitting
Concave
Polygons
We can identify a concave polygon by calculating ...
Identifying
a
concave polygon by calculating cross
products of successive pairsof edge vectors.
some cross products
is
positive while others have
a
negative
z
component, we
have a concave polygon. ... For concave polygon-clipping re-
gions,
we
can still apply these parametric clipping procedures if we first split the
concave polygon into a set of convex poiygons.
Circles or other curved-boundary...
...
Identifying
a
concave polygon by calculating cross
products of successive pairsof edge vectors.
some cross products
is
positive while others have
a
negative
z
component, we
have a concave polygon. ...
Area Clipping (polygons)
Curve Clipping
Text Clipp~ng
Line and polygon clipping routines
are
standard components of graphics pack-
ages, but many packages accommodate curved objects, particularly ... coordinate conversion.
Since rotation calculations quire trignometric evaluations and several
multiplications for each transformed point, computational efficiency can become
an important consideration...
... noecho)
;
I
/*
set buttons to choice device. event mode
*/
1
setChoiceMode
(1,
6.
event, noechol
;
do
(
awaitEvent
(60,
vs, deviceclass, devicecode):
if (deviceclass
==
choice) ... electronic circuit schematics, are commonly put together using com-
puter-aided design methods. Graphical methods are used also for representing
economic, financial, organizational, scientific, ... lines according to connection
rules that are speclfied with each gate description. The basic symbols
in
this hier-
archical description
are
the logic gates. Although the gates themselves could...
... objects
according to the lighting conditions in the scene and according to assigned sur-
face characteristics.
Lighhng
speclhcations include the intensity and positions of
light sources ... Some atmospheric effects can change the perceived color of an object, and
we can model these effects with depth cueing.
Visible Line and Surface Identification
We can also clarify depth
... three control points of the previous section as
Requiring second-order continuity of Mzier curve sections can be unnecessarily
restrictive. This is especially true with cubic curves, which have...