Sponsored Content
Homework and Emergencies Homework & Coursework Questions Bounded Buffer is hanging, tried all I can. (C++) Post 302733381 by Corona688 on Tuesday 20th of November 2012 10:18:37 AM
Old 11-20-2012
If you lock the global-lock, they try and fail to get data, both will stay locked until the writer adds more -- which it can't because the global lock is stuck locked.

For single-reader and single-writer, just two semaphores should do -- one for read, one for write. Keep the read and write separate and they shouldn't stomp on each other.

Procedure for writing:
1) Wait on write-sem
2) Add data to array
3) Increment and wrap write position
4) Post on read-sem

Procedure for reading:
1) Wait on read-sem
2) Copy element from array
3) Increment and wrap read position
4) Post on write-sem

If you want these to work with multiple readers or multiple writers, you will need a global mutex around items 2 and 3, but only lock the global mutex after you've waited on the read or write sem! Otherwise you'll deadlock(reader blocking for more data, writer can't add more data because the global mutex is locked).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Hanging commands

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)
Discussion started by: jOOc
0 Replies

2. Solaris

hanging sockets!??!

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)
Discussion started by: Naanu
1 Replies

3. UNIX for Dummies Questions & Answers

Hanging port?

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)
Discussion started by: NycUnxer
1 Replies

4. Shell Programming and Scripting

Script is hanging

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)
Discussion started by: rakeshsr12
1 Replies

5. Programming

bounded buffer implementation

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)
Discussion started by: amejoish
15 Replies

6. Solaris

df command hanging

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)
Discussion started by: vivek.goel.piet
10 Replies

7. Shell Programming and Scripting

nslookup hanging

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)
Discussion started by: Bearwhale
2 Replies

8. Shell Programming and Scripting

sed hanging

/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)
Discussion started by: SkySmart
2 Replies

9. Shell Programming and Scripting

Sftp hanging

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)
Discussion started by: Girish19
0 Replies

10. Shell Programming and Scripting

XML text bounded with tag

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
pthread_rwlockattr_init(3T)											       pthread_rwlockattr_init(3T)

NAME
pthread_rwlockattr_init(), pthread_rwlockattr_destroy() - initialize or destroy a read-write lock attributes object SYNOPSIS
PARAMETERS
attr Pointer to the read-write lock attributes object to be initialized or destroyed. DESCRIPTION
initializes the read-write lock attributes object attr with the default value for all attributes. The attributes object describes a read- write lock in detail and is passed to the read-write lock initialization function. When a read-write lock attributes object is used to initialize a read-write lock, the values of the individual attributes determine the characteristics of the new read-write lock. Attributes objects act like additional parameters to object initialization. After a read-write lock attributes object has been used to initialize one or more read-write lock, any function affecting the attributes object does not affect the previously initialized read-write locks. The read-write lock attributes and their default values are: The default value is If an initialized read-write lock attributes object is reinitialized, undefined behavior results. destroys the read-write lock attributes object attr. The destroyed read-write lock attributes object ceases to exist and its resources are reclaimed. Referencing the object after it has been destroyed results in undefined behavior. A destroyed read-write lock attributes object can be reinitialized using the function Read-write locks which have been already initialized using this attributes object are not affected by the destruction of the read-write lock attributes object. RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set). ERRORS
For each of the following conditions, if the condition is detected, the and functions return the corresponding error number: [ENOMEM] There is insufficient memory available in which to initialize attr. [EINVAL] The value specified by attr is invalid. AUTHOR
and were developed by X/Open. SEE ALSO
pthread_create(3T), pthread_rwlockattr_getpshared(3T), pthread_rwlockattr_setpshared(3T), pthread_rwlock_init(3T). STANDARDS CONFORMANCE
Pthread Library pthread_rwlockattr_init(3T)
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy