Podcast
Questions and Answers
To position a text file, whence has to be SEEK_______
To position a text file, whence has to be SEEK_______
SET
The function used to set the stream to the beginning of the file is called ______
The function used to set the stream to the beginning of the file is called ______
rewind
The data type used for file positions that can be larger than 32 bits is called ______
The data type used for file positions that can be larger than 32 bits is called ______
off_t
The ______ function stores the current value of the file's position indicator.
The ______ function stores the current value of the file's position indicator.
Signup and view all the answers
Formatted output in C is handled by the five ______ functions.
Formatted output in C is handled by the five ______ functions.
Signup and view all the answers
We have to call the device-specific function to obtain a file ______ because special types of files cannot be opened with the standard I/O fopen function.
We have to call the device-specific function to obtain a file ______ because special types of files cannot be opened with the standard I/O fopen function.
Signup and view all the answers
The standard I/O system can differentiate between a text file and a ______ file using the character b as part of the type.
The standard I/O system can differentiate between a text file and a ______ file using the character b as part of the type.
Signup and view all the answers
The fdopen function is part of ______.1, while fopen and freopen are part of ISO C.
The fdopen function is part of ______.1, while fopen and freopen are part of ISO C.
Signup and view all the answers
When a file is opened with a type of append, each ______ will take place at the current end of file.
When a file is opened with a type of append, each ______ will take place at the current end of file.
Signup and view all the answers
The O_APPEND flag must be set to correctly support the ______ mode when multiple processes are involved.
The O_APPEND flag must be set to correctly support the ______ mode when multiple processes are involved.
Signup and view all the answers
The fdopen function cannot simply ______ any file it opens for writing.
The fdopen function cannot simply ______ any file it opens for writing.
Signup and view all the answers
Versions of fopen from Berkeley before 4.4BSD do not handle the append mode ______.
Versions of fopen from Berkeley before 4.4BSD do not handle the append mode ______.
Signup and view all the answers
When a file is opened for reading and writing, two ______ apply.
When a file is opened for reading and writing, two ______ apply.
Signup and view all the answers
The tmpnam function generates a string that is a valid ______ and does not match the name of any existing file.
The tmpnam function generates a string that is a valid ______ and does not match the name of any existing file.
Signup and view all the answers
The tmpfile function creates a temporary binary file of type ______ that is automatically removed when it is closed.
The tmpfile function creates a temporary binary file of type ______ that is automatically removed when it is closed.
Signup and view all the answers
TMP_MAX is defined in ______, and its minimum value is at least 25.
TMP_MAX is defined in ______, and its minimum value is at least 25.
Signup and view all the answers
If ptr is NULL, the generated pathname is stored in a ______ area.
If ptr is NULL, the generated pathname is stored in a ______ area.
Signup and view all the answers
The tmpnam function is marked ______ in SUSv4.
The tmpnam function is marked ______ in SUSv4.
Signup and view all the answers
Line buffering is typically used on a stream when it refers to a ______.
Line buffering is typically used on a stream when it refers to a ______.
Signup and view all the answers
The standard I/O library does not buffer the characters in an ______ stream.
The standard I/O library does not buffer the characters in an ______ stream.
Signup and view all the answers
Standard error is normally ______ so that any error messages are displayed as quickly as possible.
Standard error is normally ______ so that any error messages are displayed as quickly as possible.
Signup and view all the answers
When writing to a line-buffered stream, data is flushed when a ______ is written.
When writing to a line-buffered stream, data is flushed when a ______ is written.
Signup and view all the answers
All other streams are line buffered if they refer to a ______ device.
All other streams are line buffered if they refer to a ______ device.
Signup and view all the answers
Standard input and standard output are fully buffered, if they do not refer to an ______ device.
Standard input and standard output are fully buffered, if they do not refer to an ______ device.
Signup and view all the answers
The size of the buffer used by the standard I/O library for line buffering is ______.
The size of the buffer used by the standard I/O library for line buffering is ______.
Signup and view all the answers
Most implementations default to standard error being ______.
Most implementations default to standard error being ______.
Signup and view all the answers
The family of functions that parses an input string and converts character sequences into variables is called ______.
The family of functions that parses an input string and converts character sequences into variables is called ______.
Signup and view all the answers
The format specification for the scanf family begins with a percent sign [%] which indicates the beginning of a ______.
The format specification for the scanf family begins with a percent sign [%] which indicates the beginning of a ______.
Signup and view all the answers
If a character in the input does not match the format specification, processing stops, leaving the remainder of the input ______.
If a character in the input does not match the format specification, processing stops, leaving the remainder of the input ______.
Signup and view all the answers
An optional leading asterisk in the conversion specification is used to suppress ______.
An optional leading asterisk in the conversion specification is used to suppress ______.
Signup and view all the answers
The ______ component in the conversion specification specifies the maximum field width in characters.
The ______ component in the conversion specification specifies the maximum field width in characters.
Signup and view all the answers
The lenmodifier component specifies the size of the argument to be initialized with the result of the ______.
The lenmodifier component specifies the size of the argument to be initialized with the result of the ______.
Signup and view all the answers
Results stored in unsigned types can optionally be signed on input, for example, --1 will scan as ______ into an unsigned integer.
Results stored in unsigned types can optionally be signed on input, for example, --1 will scan as ______ into an unsigned integer.
Signup and view all the answers
The field that specifies the type of conversion is known as ______ in the scanf functions.
The field that specifies the type of conversion is known as ______ in the scanf functions.
Signup and view all the answers
When we increase the amount of data in the stream's buffer and call ______, a null byte is written at the current position in the stream.
When we increase the amount of data in the stream's buffer and call ______, a null byte is written at the current position in the stream.
Signup and view all the answers
The sample program seeds the buffer with a known pattern to observe how writes to the ______ behave.
The sample program seeds the buffer with a known pattern to observe how writes to the ______ behave.
Signup and view all the answers
The defined buffer size in the program is set to ______.
The defined buffer size in the program is set to ______.
Signup and view all the answers
The initial buffer contents are printed using ______ function.
The initial buffer contents are printed using ______ function.
Signup and view all the answers
The function ______ is used to flush the output buffer to the file stream.
The function ______ is used to flush the output buffer to the file stream.
Signup and view all the answers
The function ______ sets the position of the file pointer to the beginning of the stream.
The function ______ sets the position of the file pointer to the beginning of the stream.
Signup and view all the answers
After calling ______, a null byte is added to the end of the string in the buffer.
After calling ______, a null byte is added to the end of the string in the buffer.
Signup and view all the answers
The memory stream flush policy is highlighted in the example by the program running on ______.
The memory stream flush policy is highlighted in the example by the program running on ______.
Signup and view all the answers
When the program reaches the ______ step, it indicates the end of the buffer manipulations.
When the program reaches the ______ step, it indicates the end of the buffer manipulations.
Signup and view all the answers
In the initial output, the length of the string in the buffer after the flush is ______.
In the initial output, the length of the string in the buffer after the flush is ______.
Signup and view all the answers
In Solaris, both threads have the same process ID, but different ______ IDs.
In Solaris, both threads have the same process ID, but different ______ IDs.
Signup and view all the answers
FreeBSD uses a pointer to the thread data structure for its thread ______.
FreeBSD uses a pointer to the thread data structure for its thread ______.
Signup and view all the answers
The Linux thread IDs look like pointers, even though they are represented as unsigned long ______.
The Linux thread IDs look like pointers, even though they are represented as unsigned long ______.
Signup and view all the answers
Linux 2.4 implemented each thread with a separate ______.
Linux 2.4 implemented each thread with a separate ______.
Signup and view all the answers
The implementation was overhauled to use a new threads implementation called the Native POSIX Thread ______.
The implementation was overhauled to use a new threads implementation called the Native POSIX Thread ______.
Signup and view all the answers
In Mac OS X, the thread ID for the main thread is from a different ______ range than other threads.
In Mac OS X, the thread ID for the main thread is from a different ______ range than other threads.
Signup and view all the answers
When comparing thread IDs, looking at them in hexadecimal format makes them more ______.
When comparing thread IDs, looking at them in hexadecimal format makes them more ______.
Signup and view all the answers
The program runs under different operating systems, showcasing the variances in thread ______.
The program runs under different operating systems, showcasing the variances in thread ______.
Signup and view all the answers
We need to recheck the condition to see whether we still need to free the ______.
We need to recheck the condition to see whether we still need to free the ______.
Signup and view all the answers
The structure mutex can be used to protect everything else in the ______ structure.
The structure mutex can be used to protect everything else in the ______ structure.
Signup and view all the answers
We can simplify things considerably by using the hash list lock to protect the structure ______ count.
We can simplify things considerably by using the hash list lock to protect the structure ______ count.
Signup and view all the answers
If another thread found the structure and added a ______ to it while we blocked.
If another thread found the structure and added a ______ to it while we blocked.
Signup and view all the answers
The hashlock is initialized with ______ in pthread mutex.
The hashlock is initialized with ______ in pthread mutex.
Signup and view all the answers
Eah foo object has a mutex called ______ to manage concurrent access.
Eah foo object has a mutex called ______ to manage concurrent access.
Signup and view all the answers
The hash function used is defined as ______(id) (((unsigned long)id)%NHASH).
The hash function used is defined as ______(id) (((unsigned long)id)%NHASH).
Signup and view all the answers
If allocation fails, the function should return ______.
If allocation fails, the function should return ______.
Signup and view all the answers
Reader--writer locks are similar to mutexes, except that they allow for higher degrees of ______.
Reader--writer locks are similar to mutexes, except that they allow for higher degrees of ______.
Signup and view all the answers
In a reader--writer lock, only one thread at a time can hold a lock in ______ mode.
In a reader--writer lock, only one thread at a time can hold a lock in ______ mode.
Signup and view all the answers
When a reader--writer lock is ______ locked, all threads attempting to lock it in write mode are blocked.
When a reader--writer lock is ______ locked, all threads attempting to lock it in write mode are blocked.
Signup and view all the answers
Reader--writer locks are particularly effective in scenarios where data structures are read more often than they are ______.
Reader--writer locks are particularly effective in scenarios where data structures are read more often than they are ______.
Signup and view all the answers
Multiple threads can hold a reader--writer lock in ______ mode at the same time.
Multiple threads can hold a reader--writer lock in ______ mode at the same time.
Signup and view all the answers
If a lock is already held in read mode, reader--writer locks usually block additional ______ from acquiring the lock.
If a lock is already held in read mode, reader--writer locks usually block additional ______ from acquiring the lock.
Signup and view all the answers
In practice, deliberately locking a mutex that it already owns may lead to ______.
In practice, deliberately locking a mutex that it already owns may lead to ______.
Signup and view all the answers
Some operating systems, like Mac OS X 10.6.8, do not support ______.
Some operating systems, like Mac OS X 10.6.8, do not support ______.
Signup and view all the answers
The function to acquire a lock in shared mode is called pthread__rwlock__rdlock, and it returns ______ if OK.
The function to acquire a lock in shared mode is called pthread__rwlock__rdlock, and it returns ______ if OK.
Signup and view all the answers
When acquiring a write lock, you should check the return value of pthread__rwlock__wrlock for ______.
When acquiring a write lock, you should check the return value of pthread__rwlock__wrlock for ______.
Signup and view all the answers
If a lock can be acquired, the pthread__rwlock__tryrdlock function will return ______.
If a lock can be acquired, the pthread__rwlock__tryrdlock function will return ______.
Signup and view all the answers
A barrier allows each thread to wait until all cooperating threads have reached the same ______.
A barrier allows each thread to wait until all cooperating threads have reached the same ______.
Signup and view all the answers
If the lock is busy, pthread__rwlock__trywrlock returns the error ______.
If the lock is busy, pthread__rwlock__trywrlock returns the error ______.
Signup and view all the answers
The ______ function acts as a barrier to allow one thread to wait until another thread exits.
The ______ function acts as a barrier to allow one thread to wait until another thread exits.
Signup and view all the answers
The pthread__rwlock__unlock function is used to ______ the lock after its use.
The pthread__rwlock__unlock function is used to ______ the lock after its use.
Signup and view all the answers
We can use the pthread_barrier_init function to ______ a barrier.
We can use the pthread_barrier_init function to ______ a barrier.
Signup and view all the answers
An uninitialized lock can lead to ______, which is a state where threads are stuck waiting for each other.
An uninitialized lock can lead to ______, which is a state where threads are stuck waiting for each other.
Signup and view all the answers
Reader-writer locks allow multiple threads to acquire a lock in ______ mode simultaneously.
Reader-writer locks allow multiple threads to acquire a lock in ______ mode simultaneously.
Signup and view all the answers
The resources allocated for the barrier will be freed when we call the pthread_barrier_______ function.
The resources allocated for the barrier will be freed when we call the pthread_barrier_______ function.
Signup and view all the answers
A queue of job requests can be protected by a single reader-writer ______.
A queue of job requests can be protected by a single reader-writer ______.
Signup and view all the answers
When initializing a barrier, we use the ______ argument to specify the number of threads needed to proceed.
When initializing a barrier, we use the ______ argument to specify the number of threads needed to proceed.
Signup and view all the answers
We use the pthread_barrier_wait function to indicate that a thread is ______ with its work.
We use the pthread_barrier_wait function to indicate that a thread is ______ with its work.
Signup and view all the answers
Barriers allow an ______ number of threads to wait until all of them have completed processing.
Barriers allow an ______ number of threads to wait until all of them have completed processing.
Signup and view all the answers
The ______ argument may be set to NULL to initialize a barrier with the default attributes.
The ______ argument may be set to NULL to initialize a barrier with the default attributes.
Signup and view all the answers
The function pthread_cond_signal is used to ______ the thread or condition.
The function pthread_cond_signal is used to ______ the thread or condition.
Signup and view all the answers
In order to synchronize threads, we need to protect the condition with a ______.
In order to synchronize threads, we need to protect the condition with a ______.
Signup and view all the answers
When putting a message on the queue, we must hold the ______.
When putting a message on the queue, we must hold the ______.
Signup and view all the answers
The state of the work queue is referred to as the ______.
The state of the work queue is referred to as the ______.
Signup and view all the answers
After releasing the mutex, we can call pthread_cond_signal and it is okay for a thread to pull the message off the queue before we ______ the mutex.
After releasing the mutex, we can call pthread_cond_signal and it is okay for a thread to pull the message off the queue before we ______ the mutex.
Signup and view all the answers
We evaluate the condition in a ______ loop.
We evaluate the condition in a ______ loop.
Signup and view all the answers
Pthread_cond_wait is called to release the ______ and wait for the condition variable.
Pthread_cond_wait is called to release the ______ and wait for the condition variable.
Signup and view all the answers
The message structure includes a pointer to the next message, called ______.
The message structure includes a pointer to the next message, called ______.
Signup and view all the answers
Flashcards
Line Buffered Streams
Line Buffered Streams
Output is collected in a buffer until a newline character is encountered, then written to the destination.
Line Buffering Caveats
Line Buffering Caveats
Buffer size is fixed: Output may happen before newline if filled. All line-buffered output flushes when unbuffered input is requested.
Unbuffered Streams
Unbuffered Streams
Characters are output immediately without buffering.
Standard Error
Standard Error
Signup and view all the flashcards
Fully Buffered Streams
Fully Buffered Streams
Signup and view all the flashcards
Interactive Devices (Streams)
Interactive Devices (Streams)
Signup and view all the flashcards
Standard Input/Output Buffering
Standard Input/Output Buffering
Signup and view all the flashcards
Standard I/O Library
Standard I/O Library
Signup and view all the flashcards
Text file positioning
Text file positioning
Signup and view all the flashcards
fseeko() and ftello()
fseeko() and ftello()
Signup and view all the flashcards
whence = SEEK_SET
whence = SEEK_SET
Signup and view all the flashcards
fgetpos() and fsetpos()
fgetpos() and fsetpos()
Signup and view all the flashcards
Formatted output functions
Formatted output functions
Signup and view all the flashcards
fdopen function
fdopen function
Signup and view all the flashcards
fopen function
fopen function
Signup and view all the flashcards
append mode (file)
append mode (file)
Signup and view all the flashcards
O_APPEND flag
O_APPEND flag
Signup and view all the flashcards
File descriptor
File descriptor
Signup and view all the flashcards
Binary File
Binary File
Signup and view all the flashcards
lseek function
lseek function
Signup and view all the flashcards
Read/Write File
Read/Write File
Signup and view all the flashcards
tmpnam function
tmpnam function
Signup and view all the flashcards
tmpnam return value (ptr NULL)
tmpnam return value (ptr NULL)
Signup and view all the flashcards
tmpnam return value (ptr not NULL)
tmpnam return value (ptr not NULL)
Signup and view all the flashcards
tmpfile function
tmpfile function
Signup and view all the flashcards
TMP_MAX constant
TMP_MAX constant
Signup and view all the flashcards
scanf family functions
scanf family functions
Signup and view all the flashcards
Return value of scanf family
Return value of scanf family
Signup and view all the flashcards
Conversion specification
Conversion specification
Signup and view all the flashcards
Conversion specification start
Conversion specification start
Signup and view all the flashcards
Suppress conversion
Suppress conversion
Signup and view all the flashcards
Field width
Field width
Signup and view all the flashcards
Length Modifiers
Length Modifiers
Signup and view all the flashcards
Conversion Types
Conversion Types
Signup and view all the flashcards
Null byte in memory streams
Null byte in memory streams
Signup and view all the flashcards
Buffer flushing
Buffer flushing
Signup and view all the flashcards
fclose function
fclose function
Signup and view all the flashcards
Memory stream
Memory stream
Signup and view all the flashcards
Buffer
Buffer
Signup and view all the flashcards
Memory stream buffer behavior
Memory stream buffer behavior
Signup and view all the flashcards
fflush function
fflush function
Signup and view all the flashcards
seek operations
seek operations
Signup and view all the flashcards
Thread ID on Solaris
Thread ID on Solaris
Signup and view all the flashcards
Thread ID on FreeBSD
Thread ID on FreeBSD
Signup and view all the flashcards
Thread ID on Mac OS X
Thread ID on Mac OS X
Signup and view all the flashcards
Thread ID on Linux 2.4
Thread ID on Linux 2.4
Signup and view all the flashcards
Thread ID on Linux 2.6
Thread ID on Linux 2.6
Signup and view all the flashcards
NPTL (Native POSIX Thread Library)
NPTL (Native POSIX Thread Library)
Signup and view all the flashcards
Thread ID on Linux 2.6
Thread ID on Linux 2.6
Signup and view all the flashcards
Thread ID on Linux 2.6
Thread ID on Linux 2.6
Signup and view all the flashcards
What is the problem with the initial locking approach?
What is the problem with the initial locking approach?
Signup and view all the flashcards
How is the locking improved?
How is the locking improved?
Signup and view all the flashcards
What is the purpose of the hash lock in this example?
What is the purpose of the hash lock in this example?
Signup and view all the flashcards
Why is the foo
structure mutex separate?
Why is the foo
structure mutex separate?
Signup and view all the flashcards
What is the purpose of the f_count
variable?
What is the purpose of the f_count
variable?
Signup and view all the flashcards
How is the structure linked into the hash list?
How is the structure linked into the hash list?
Signup and view all the flashcards
What is the purpose of the pthread_mutex_init
function?
What is the purpose of the pthread_mutex_init
function?
Signup and view all the flashcards
Why is the f_lock
mutex acquired after the hash lock?
Why is the f_lock
mutex acquired after the hash lock?
Signup and view all the flashcards
pthread_rwlock_rdlock
pthread_rwlock_rdlock
Signup and view all the flashcards
pthread_rwlock_wrlock
pthread_rwlock_wrlock
Signup and view all the flashcards
pthread_rwlock_unlock
pthread_rwlock_unlock
Signup and view all the flashcards
pthread_rwlock_tryrdlock
pthread_rwlock_tryrdlock
Signup and view all the flashcards
pthread_rwlock_trywrlock
pthread_rwlock_trywrlock
Signup and view all the flashcards
Reader--Writer Lock
Reader--Writer Lock
Signup and view all the flashcards
What are the advantages of using reader--writer locks?
What are the advantages of using reader--writer locks?
Signup and view all the flashcards
Mutex Lock
Mutex Lock
Signup and view all the flashcards
Deadlock
Deadlock
Signup and view all the flashcards
pthread_mutex_timedlock()
pthread_mutex_timedlock()
Signup and view all the flashcards
Write Lock
Write Lock
Signup and view all the flashcards
Read Lock
Read Lock
Signup and view all the flashcards
Starvation
Starvation
Signup and view all the flashcards
Reader-Writer Locks Suitability
Reader-Writer Locks Suitability
Signup and view all the flashcards
Condition Variable
Condition Variable
Signup and view all the flashcards
pthread_cond_signal
pthread_cond_signal
Signup and view all the flashcards
pthread_cond_broadcast
pthread_cond_broadcast
Signup and view all the flashcards
Mutex (Mutual Exclusion)
Mutex (Mutual Exclusion)
Signup and view all the flashcards
pthread_cond_wait
pthread_cond_wait
Signup and view all the flashcards
Synchronization
Synchronization
Signup and view all the flashcards
Condition Variable Usage
Condition Variable Usage
Signup and view all the flashcards
Why use a while loop?
Why use a while loop?
Signup and view all the flashcards
Barrier
Barrier
Signup and view all the flashcards
pthread_barrier_init
pthread_barrier_init
Signup and view all the flashcards
pthread_barrier_destroy
pthread_barrier_destroy
Signup and view all the flashcards
pthread_barrier_wait
pthread_barrier_wait
Signup and view all the flashcards
Count (Barrier initialization)
Count (Barrier initialization)
Signup and view all the flashcards
Attributes (Barrier initialization)
Attributes (Barrier initialization)
Signup and view all the flashcards
Barrier Usage
Barrier Usage
Signup and view all the flashcards
Synchronization Mechanism
Synchronization Mechanism
Signup and view all the flashcards
Study Notes
Standard I/O Library
- Specified by ISO C standard
- Implemented on many operating systems
- Additional interfaces as extensions by the Single UNIX Specification
- Handles buffer allocation and optimal-sized I/O chunks
- Written by Dennis Ritchie around 1975
- Major revision of Portable I/O library by Mike Lesk
- Little change in the standard I/O library after 35 years
Streams and FILE Objects
- I/O routines centered on file descriptors
- File opened, descriptor returned, then used for I/O operations
- Standard I/O library uses the concept of streams
- Stream is associated with a file when it's opened/created with the standard I/O library
- Characters represented by bytes. International character sets use multiple bytes
- Streams can have byte or wide orientation
- Orientation can be set to wide when wide character functions are used or byte when byte functions are used
- freopen function and fwide function handle stream orientation changes
Standard Input, Standard Output, and Standard Error
- Predefined streams: standard input, standard output, standard error
- Associated with file descriptors STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
- Referenced through predefined file pointers stdin, stdout, stderr
Buffering
- Goal of buffering: minimum number of read/write calls
- Standard I/O library does buffering automatically
- Three types of buffering
- Fully buffered: I/O occurs when the buffer is filled (files on disk often use this).
- Line buffered: I/O occurs when a newline character is encountered (typically used on terminals).
- Unbuffered: No buffering of characters
Opening a Stream
- fopen function opens a specified file
- freopen function opens a file on a specific stream while closing the current one if already open
- fdopen function associates a standard I/O stream with an existing file descriptor.
Binary I/O
- Functions fread and fwrite used for binary data operations
- Specify size and number of elements to read or write.
Positioning a Stream
- ftell, fseek, fseeko, ftello, fgetpos, and fsetpos functions used for stream positioning
- Binary files position is measured in bytes from the beginning of the file.
- Text files position cannot always be measured as a simple byte offset
Formatted Output
- printf, fprintf, dprintf, sprintf, and snprintf functions used for formatted output
- Format specification controls how arguments are converted for assignment
- Optional components (flags, field width, precision, length modifiers) for customization
Formatted Input
- scanf, fscanf, and sscanf functions used for formatted input
- Format specification controls how user input is interpreted
- Arguments (addresses) following the format string receive the converted data
Implementation Details
- Fileno function is used to obtain the file descriptor associated with a stream
- Stdio.h header, which defines the file stream object, flags, and macro-based functions.
Temporary Files
- tmpnam function creates a valid, unique pathname for a temporary file
- tmpfile function creates and opens a temporary binary file that is automatically deleted when closed
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz covers the essentials of the Standard I/O Library as specified by the ISO C standard. It highlights its implementation across operating systems, the concept of streams, and file descriptor usage, including the management of stream orientation and additional functionalities. Test your knowledge on the historical context and technical details of this fundamental programming interface.