[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference azur::mcc

Title:DECmcc user notes file. Does not replace IPMT.
Notice:Use IPMT for problems. Newsletter location in note 6187
Moderator:TAEC::BEROUD
Created:Mon Aug 21 1989
Last Modified:Wed Jun 04 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:6497
Total number of notes:27359

670.0. "Proper use of threads to synch up code" by SMAUG::DPETERSON () Tue Jan 29 1991 08:20

My question is how you get a line of code to wait for other events
(soft interrupts) before continuing. 

For example suppose I want my module to perform an orderly shutdown in a
specified period of time. I want all my running threads to clean up but I'm
only willing to wait for a specified time. After reading and beginning to
understand the thread environment I think the solution uses two new 
threads as:

thread 1
    create an alerter thread that sends alerts to all running threads
    and waits for them to complete mcc_thread_join_all()

thread 2
    create a timer thread that waits for the specified shutdown time
    mcc_timer_wait()
    
main line code
    And the synchronization is done by waiting for either of these two,
    thread 1 or thread 2 to complete, mcc_thread_join_any(). Then exit()
    leaving any possible threads in an unknown state.

This is only one example of where I need this functionality.

Is this the proper technique?

Is it the only one?

Regards
Dave

T.RTitleUserPersonal
Name
DateLines
670.1alerting a thread performing sys$qiowPETE::BURGESSTue Jan 29 1991 16:1361
Alerting of intercepted routines:

Some system services are revectored to framework thread
synchronous routines in order to provide concurrency
of cpu work and i/o work, particularly those
system routines which might block the process for 
an indefinite length of time.

For this reason the framework should perform special
work to assist in alerting threads which may
be blocked for an indefinitely long period of time,
eg sys$qiow read operation from a logical link or
a terminal input stream...

For a sys$qiow operation, the framework replacement routine
    o issues a $qio operation
    o blocks the thread until either an
    	ast fires or the thread receives an alert.
    o if an alert is received, then the rtn
    	performs sys$cancel on the channel;
    	then waits until the i/o operation is completed
    	(VMS return either io$_abort or io$_cancel in iosb)
    
    The client of the sys$qiow should check to see
    whether or not an i/o (iosb) error of io$_cancel or io$_abort
    was triggered by an alert by issuing a
    mcc_thread_test_alert () function call.


For a rms get operation, I didn't know how to
cancel the current operation when the replacement
routine discovered that an alert was pending.
Consequently, the rtn just stays in the wait loop
until the i/o completes.  For rms get on a terminal
input stream, fortunately rms its aborts the operation
so there is no problem.  If one was doing transparent
decnet input via rms, then there would be a problem
for the thread would block indefinitely until the
input request was completed.  I suppose that
the framework replacement routine could have
reached into the fab/rab and pulled out the 
channel # and performed a cancel operation with it.

A quick scan of the
relevant source module found that sys$qiow is the ONLY
intercepted routine which performs special alert handling.
(Not to be fixed before v1.2)  


The "main routine" thread is alertable like 
any other thread.  It has two special attributes:
(1) its stack is extensible (controlled by vms)
(2) when the main routine returns, then 
    the exit handlers and inner mode run-down routines are
    run (so don't try to join with the main routine thread)


Your example is how the mcc main routine does the job.
For v1.1 the time interval will be a function of the number
of outstanding threads, rather than just a fixed time limit.

670.2it will workGOSTE::CALLANDERWed Jan 30 1991 14:1612
    RE .0
    
    What you are proposing is almost exactly the algorythmn that is
    used in the Notification FM. The only difference is that since the
    NOTIFY request is always run in a seperate thread  we don't really
    care about waiting for only a specified period of time. We are more
    concerned with if a thread returns back an error while attempting
    to alert it, or if the join fails. when cleaning up remember you
    need to recover that lost memory, if you simply exit the threads
    without correctly terminating their operation you will not recover
    any dynamically allocated memory that has not been freed.