Although, I'm still not clear why this should work if I have more than 5 threads of each going. That would leave the extras in limbo or something?)
The simplest model is with a mutex - like pthread_mutex_t
pseudo code
Do the exact same thing with write or send. Only keep the mutex during the read or write. Do nothing else when you own the mutex.
This model is fine for the situation where you have some processing to do with data, and you read/write and process using threads. I/O is always slower than other operations.
If you have almost no processing to do then threads are not going to gain you much if anything. Your app will always be I/O bound whether it is threaded or not. The idea with threads is to do data crunching or whatever in parallel. When parallelism gains you nothing, skip threading. So if you are misusing threading, then other threads are in fact superfluous.
To avoid hanging on pthread_join, make the threads not joinable, when they return or call
they simply go away.
Hello,
I just tried to run this command: /usr/lib/sendmail -d0.1 -bt < /dev/null | grep -i version
Its doing what I want: writing out the sendmail version.
But on some machines it writing the version and then exit to the prompt but on others its writing the version but then hangs, I need to... (0 Replies)
hi all,
i had a program which created a socket on port 7113, but for some reason the program was hunbg and I had to Ctrl+c it. I ran the program for a couple of times and now when I do a netstat -a I see that these sockets are lingering and that might be the reason why my program is not... (1 Reply)
Ok, this question my be different. I can ping our unix box, but when we I to access the webpage I cant. To access the webpage I type http://ipaddress:some port. How do I check if a port is hanging and how would I un hang it. Sorry if question doesnt make sense. (1 Reply)
Hello,
I have the following shell script and when i execute, it keeps hanging and nothing happens
Please let me know.
Requirement is to read data from file and pass it to the sql and create files as shown.
code
/********
#!/bin/sh
while read user.dat
do
echo "user = $1 email =... (1 Reply)
Hi Experts,
I have a programming assignment that asks us to implement a pipegrep function. it basically has 5 stages and each stage has a thread and buffers are used between stages.
am currently implementing stage 1 . In stage 1 am suppose to read directory and store the filenames in buffer1... (15 Replies)
Hi Folks,
When i execute the command df -kh in my system the o/p hangs..
The command runs fine but takes a lot of time before coming back to the # prompt.
Can anyone please suggest the possible cause and solution?. (10 Replies)
Hey folks. Long time lurker, first time poster. I'm a bit of a newbie at "coding" (obviously, scripting is a teensy bit different than coding) and I've run into a problem that I just can't seem to get around.
I'm going through a list of servers to check their name, IP, reverse-NSLOOKUP name and... (2 Replies)
/bin/sed -n '$q;5633653,0 p' lfile
lfile is a log file that is being updated several times a second.
so, the command above figures out the line number it wants in the lfile and then proceeds to output all lines from that line number to the end of the file.
the problem is, the end of the... (2 Replies)
Hi All,
I am transfering a file through sftp. But the script is hanging at exit occasionally.
I am suspecting that sftp is hanging due to buffer size issue.
If that is the case can any body suggest a solution.
Please find the code.
echo "cd /${CUST_ID}/inbound/${SAFET_ID}" >... (0 Replies)
Could you please give your inputs on the below issue:
source.xml
<?xml version="1.0" encoding="UTF-16"?>
<P1 >
<C1 type="i"><2></C1>
<V1 type="string"><6.2></V1>
<D1 type="string">
<D2><1.0></D2>
<D2><2.0></D2>
</D1>
......................
......................
many more... (7 Replies)
Discussion started by: unme
7 Replies
LEARN ABOUT HPUX
pthread_mutex_lock
pthread_mutex_lock(3T)pthread_mutex_lock(3T)NAME
pthread_mutex_lock(), pthread_mutex_trylock() - lock or attempt to lock a mutex
SYNOPSIS PARAMETERS
mutex Pointer to the mutex to be locked.
DESCRIPTION
The mutex object mutex is locked by calling the function. How the calling thread acquires the mutex is dependent upon the type attribute
for the mutex. This operation returns with the mutex object referenced by mutex in the locked state with the calling thread as its owner.
If the mutex type is deadlock detection is not provided. Attempting to relock the mutex causes deadlock. If a thread attempts to unlock a
mutex that it has not locked or a mutex which is unlocked, undefined behavior results.
If the mutex type is the mutex maintains the concept of an owner. If a thread attempts to relock a mutex that it has already locked, an
error shall be returned. If a thread attempts to unlock a mutex that it has not locked or a mutex that is unlocked, an error shall be
returned.
If the mutex type is then the mutex maintains the concept of an owner and a lock count. When a thread successfully acquires a mutex for
the first time, the count field shall be set to one. Every time a thread relocks this mutex, the count field shall be incremented by one.
Each time the thread unlocks the mutex, the count field shall be decremented by one. When the count field reaches zero, the mutex shall
become available for other threads to acquire. If a thread attempts to unlock a mutex that it has not locked, an error shall be returned.
If the mutex type is deadlock detection is not provided. Attempting to relock the mutex causes deadlock. A thread can unlock a mutex that
it has not locked. Attempting to unlock an unlocked mutex results in undefined behavior.
If the mutex type is attempting to recursively lock the mutex results in undefined behavior. Attempting to unlock the mutex if it was not
locked by the calling thread results in undefined behavior. Attempting to unlocked the mutex if it is not locked results in undefined
behavior.
The function is identical to the function except that if the mutex object referenced by mutex cannot be acquired after one attempt, the
call returns immediately with an error.
If a signal is delivered to a thread waiting for a mutex, upon return from the signal handler, the thread shall resume waiting for the
mutex as if it was not interrupted.
RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set).
ERRORS
If any of the following occur, the and functions return the corresponding error number:
[EINVAL] mutex is a mutex and the caller's priority is higher than mutex's priority ceiling.
If any of the following occur, the function returns the corresponding error number:
[EBUSY] mutex is currently locked by another thread.
If any of the following occur, the and functions return the corresponding error number:
[EAGAIN] mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded. This error is
not detected on HP-UX.
[EINVAL] mutex is not an initialized mutex.
[EFAULT] mutex parameter points to an illegal address.
If any of the following occur, the function returns the corresponding error number:
[EDEADLK] The current thread already owns the mutex. This error will be detected only for mutexes on HP-UX.
WARNINGS
A recursive mutex can be locked more than once by the same thread without causing that thread to deadlock. Undefined behavior may result
if the owner of a recursive mutex tries to lock the mutex too many times.
AUTHOR
and was derived from the IEEE POSIX P1003.1c standard and X/Open
SEE ALSO pthread_mutex_init(3T), pthread_mutex_destroy(3T), pthread_mutex_unlock(3T).
STANDARDS CONFORMANCE
Pthread Library pthread_mutex_lock(3T)