23.07.2013 Views

HP-UX 11i Knowledge-on-Demand

HP-UX 11i Knowledge-on-Demand

HP-UX 11i Knowledge-on-Demand

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Mercury private: hg_setcrit() details<br />

hg_setcrit() can act to prevent the thread from taking<br />

involuntary c<strong>on</strong>text switches.<br />

• Useful for reducing c<strong>on</strong>tenti<strong>on</strong> <strong>on</strong> locks of critical regi<strong>on</strong>s<br />

− This helps solve the problem that if a thread holds a lock while it is switched out and the lock hold time goes up,<br />

causing other threads to have to wait for it. It is better for the lock holder to finish as fast as possible.<br />

• The kernel will usually h<strong>on</strong>or this request, but policy reas<strong>on</strong>s may require the kernel to do a c<strong>on</strong>text<br />

switch anyway. Examples:<br />

− The thread may have held off too many switches; for fairness reas<strong>on</strong>s, the kernel will begin to override the<br />

requests.<br />

− A higher-priority real-time thread may have become runnable. Higher priority time-share threads w<strong>on</strong>’t do this.<br />

• And others …<br />

• I recommend using the following c<strong>on</strong>structi<strong>on</strong> (different from man page):<br />

hg_setcrit( lock_address, UNWILLING_TO_BLOCK)<br />

acquire lock<br />

critical regi<strong>on</strong><br />

release lock<br />

hg_setcrit( CRIT_OFF, UNWILLING_TO_BLOCK )<br />

If your critical regi<strong>on</strong>s are short enough compared to your other code, this will be a win for you relative<br />

to the sequences <strong>on</strong> the man page; you will take enough c<strong>on</strong>text switches elsewhere to keep the kernel<br />

happy, and you w<strong>on</strong>’t have to take extra <strong>on</strong>es here.<br />

<str<strong>on</strong>g>HP</str<strong>on</strong>g>-<str<strong>on</strong>g>UX</str<strong>on</strong>g> <str<strong>on</strong>g>11i</str<strong>on</strong>g> v3 Training

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!