C++ :: FIFO Reads Endlessly After Closing It On Producer Side
May 10, 2012
Right after I close FIFO on the producer side, the app on the consumer side gets into an endless loop. select() returns that FIFO is ready to read. Below is the excerpt from the consumer code. The FIFO is opened "blocking" on both ends.
Code:
FifoClass fifo_r = FifoClass("/tmp/FIFO_READ");
int fdr = fifo_r.OpenR();// this->fd = open(name.c_str(), O_RDONLY , 0);
for(int i=0; ;i++) {
FD_ZERO(&rset);
FD_SET(fdr, &rset);
[Code] .....
View 2 Replies
ADVERTISEMENT
Nov 23, 2013
I am working on the producer-consumer problem and am mostly happy with what I have except for one remaining issue. I am using pthreads for consumers and producers on a FIFO, and synchronizing using a combination of semaphores and mutexes. Things seem to work fine, except that my consumers seem unable to tell when there may be more data coming into the FIFO.
I need to be able to determine not just when the FIFO is empty (it gets emptied every time a consumer thread runs) but when ALL producers have detached from it - that's when my consumers should pthread_exit, and not before that. I have read conflicting information on how FIFOs work in terms of EOF and have been unable to get it working.
(NOTE: that's what I *think* the problem is... It's my first time working with pthreads, so there may be other issues I am not even aware of).
In any case, my code is below. I am running it on a Linux VM on top of Windows, if that makes any difference. It takes 3 command line parameters - FIFO name (will be created if doesn't exist), number of producers, and number of consumers.
Code:
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
[Code].....
View 5 Replies
View Related
Oct 31, 2014
I want to write a program where one core (core 0) will fill the FIFO and other core (core 1 ) will delete the data from FIFO.
Core 0:
I create a fifo
Code:
struct node
{
int info;
struct node *ptr;
}*front,*rear,*temp,*front1;
And my en-queue function is in core 0 and writing to specific memory location..(which works perfectly)
Code:
void enq(int data)
{
if (rear == NULL)
{
rear = (struct node *)malloc(1*sizeof(struct node));
rear->ptr = NULL;
rear->info = data;
front = rear;
[Code] ....
Now the problem is in the core 1. Here I am unable to read the values from the specific memory location. I am getting garbage value. Where I am doing some stupid error.. I did not understand
Code:
(front->ptr) = (unsigned int *) memory_location;
When I print the (front->ptr) it shows correct memory address but inside the De-queue function in core 1, I am getting wrong value..
Code:
int deq(int buf[n]) {
front1 = front;
printf("Val %d ", front->info); // showing wrong value
if (front1 == NULL) {
printf("
Error: Trying to display elements from empty queue");
return 0;
[Code] ...
View 8 Replies
View Related
Dec 3, 2013
I have a school assignment to create a program that uses a producer thread to create a series of random numbers, and a consumer thread to read those numbers (via a shared bounded buffer), and record the min, max, average, and number of items. Now, the threads aren't synching well. Here's my code:
Code:
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
pthread_cond_t empty;
pthread_cond_t full;
int done = 0;
pthread_mutex_t lock;
[code] ....
And output:
Code:
Producer in for
Consumer Entering While
Consumer reading item 0
Producer making item 0
Consumer reading item 1
Consumer reading item 2
Consumer reading item 3
Producer making item 1
Producer making item 2
Producer making item 3
Producer making item 4
Producer making item 5
Producer making item 6
Consumer reading item 4
Minimum: 0
Maximum: 4978
Average: 995
Items Produced: 5
View 4 Replies
View Related
Aug 13, 2014
I compiled/built a code I had and made an executed file but when i click on it the CMD closes instantly. Is there anyway to keep this open?
View 10 Replies
View Related
Dec 7, 2014
On a right angled triangle, if the user inputs only ONE side length (not the hypotenuse) and only ONE angle, what code is required to work out the hypotenuse? I know how to work out the final side and the remaining angle once I have this.
View 4 Replies
View Related
Nov 28, 2013
I know this question must have been asked before, but the problem that I am facing is that I am using a library PoDoFo to parse PDF files. It seems that it is only compatible with C++.
Now I want the application to be web-based. That is, the user uploads a PDF file on the server, the server parses it and the parsed content is then sent back to the user.
Is such a thing possible with C++, or maybe any good work-arounds? Or should I look at server-side scripting languages like PHP and their respective libraries?
View 8 Replies
View Related
Jan 24, 2015
I am trying to switch between 2 states, and the event that determines which state i am in is based on the key i've pressed. So in this case i want the webcam to start automatically, and when key is pressed it then turns it off. The way I've done it is like this :
bool webcam_on() {
int c = 0;
VideoCapture cap(0);
if ( !cap.isOpened() ) // if not success, exit program
[Code] .....
The problem with this method is that cin.get() blocks the video stream.. I wanted something that the webcam turned on until i press some key, which would trigger the release.. How can this be done?
View 7 Replies
View Related
Nov 4, 2014
A sequence point in a C program is defined as "Any point in a program's execution at which it is gauranteed that all side effects of previous evaluations will have been performed and no side effects from subsequent evaluations have yet been performed."
What is a side effect?
View 7 Replies
View Related
Mar 4, 2015
I tried.
cin.get();
and
return 0;
is there a better way to keep the user info displaying without closing the console window.
View 1 Replies
View Related
Mar 14, 2014
The following not only closes the MDI children, but also the form I set to be an MDI container.
private void close()
{
Form[] childArray = this.MdiChildren;
foreach (Form childForm in childArray)
{
childForm.Hide();
}
}
View 5 Replies
View Related
Jan 9, 2014
... and not with a brace followed by a semicolon like in class-definitions - reason for that?
View 2 Replies
View Related
May 19, 2013
How do you add a value to the beginning of a string instead of the end?
This is for an assignment and I have to convert the user input (always assuming its a valid decimal number) to binary and store it in a string. I've got up to dividing by two to get the remainder ...
View 19 Replies
View Related
Dec 30, 2013
I am working on a 2D side scroller game. Where a ball is moving continuously towards right . I used a camera to follow the ball as soon as ball reaches the center of screen. I created a horizontal line to look like the surface on which the ball is rolling.
line runs from x=0 to x=800 (i.e screen width)
NOTE: (0,0) coordinate is at top left corner of display.
Problem: My display is 800 x 400 . Camera follows the ball, but soon the ball crosses x=800 and starts moving in black background. I want that line surface to stay there instead of going out of bound.
Additionally! I generated obstacles from x=800 which also move out of bound along with my line.
What should be done here? This is just my first c++ game project, so i might be skipping things that can solve the issue.
[Update] these screenshots manage to show, what the real problem is: [URL]
View 3 Replies
View Related
Sep 30, 2014
I'm using windows forms and I have a parent dialog box that consists of a text box and a drop-down that launches a child dialog box. The child takes user input and then prints dialog to the text box in the parent. However, the output does not appear in the text box until I close the child.
Now my question is, how do I get the text to appear without closing the child? I hit a button to send the info to the text box, but it still doesn't appear until the child closes. I also need to set up a button to suspend the child so that the user can click/copy/etc the parent.
View 7 Replies
View Related
May 3, 2014
#include<conio.h>
#include<alloc.h>
#include<string.h>
struct node
[Code]....
View 3 Replies
View Related
Jul 31, 2013
I have created a MFC dialog based application. Now I want to implement such a functionailty that I will be closing my application through command prompt. And while closing of my application the ExitInstance() method of my application should get called. What is the command which I should put in the command prompt to close my application in such a way.
View 8 Replies
View Related
Dec 17, 2014
I want to calculate the total some of delay pf receiving Side Packet . Code is as Follow ..
What is weird that even if i invoke a sleep of 2 sec ,than its show delay always zero. Delay will be in microsec ..Is there any problem with logic or anything else..
Code:
do
{#pragma omp parallel private(nthreads, tid) {
/* Obtain thread number */
tid = omp_get_thread_num();
if (tid == 0) {
nthreads = omp_get_num_threads();
[Code]...
View 2 Replies
View Related
Sep 17, 2013
I created a C program that extracts some information from computer and displays it on screen. It is completed today and is going to be applied to startup programs of domain machines. It runs at logon and takes somewhat 5-10 seconds to finish execution. The output is shown on console screen & user can either close the window by clicking on 'x' or pressing 'Ctrl+c' during execution. How do i prevent both of these events?
Basically the most time consuming processes are
Code: popen("systeminfo","r");
popen("wmic qfe get installedon","r");
1st command is getting OS name,version and hotfixes installed.
2nd command gives me the date of updates installed.
I then filter out data & print required information only.
View 3 Replies
View Related
Apr 18, 2014
[URL]
According to my project instructions, I have to make a "validation on the delete button, that before a record can be deleted it will check to see if the count of "In-Progress" orders for that product is 0. If it is greater than zero, it should not allow this record to be deleted."
So far I have on the code behind page:
protected void btnDeleteProduct_Click(object sender, EventArgs e)
{
DataView dv = (DataView)SqlOrders.Select(DataSourceSelectArguments.Empty);
[Coe].....
The professor said I have to: "As for getting the count, check your notes and book, specifically looking at SQL and the Aggregate functions. There is a function we talked about in class called "Count(OrderID)" and set the where clause to check for the productID.
View 2 Replies
View Related
Oct 11, 2014
I've found that with streamwriter(sw) the data isn't displayed with the written to document until you either leave scope or use sw.close I'd prefer to keep sw open as I will be writing to the file in and out, sometimes very frequently, but would also prefer the data to be viewed in real time. Is there an efficient way of going about this?
View 12 Replies
View Related
Aug 9, 2013
I have an C++ application which uses Microsoft Web browser ActiveX control to launch any URL within the application. The browser is embedded in C++ form and It's working fine with all the feature Microsoft has exposed through Interface(IID_IWebBrowser2).But while any url that is using session cookie has been launched, even after closing the browser the session cookies are not getting deleted. For example if user login info is stored as session cookies,the url is using the cookies and getting launched without asking for user log in info.
But if I close the browser, and again relaunch , the cookies should be deleted and the url will not find the cookies to be used for log in . That is not happening here. Although this is session cookies , it's not getting deleted and being used by embedded browser. However, if the url is launched in IE, it is behaving as expected.
So, Do I need to delete the cookies explicitly? If Yes, How to do that?
View 2 Replies
View Related
Feb 19, 2013
I have a question concerning the CDialogBar (:CControlBar).
I have a MDI application with a dockable toolbox (CDialogBar).
The user is able/allowed to move the DialogBar and to dock it at the right or left side When I dock at the left side, the content of my mdi-application (so all other open windows) are moved right (so the dockable bar moves the windows).
If i dock at the right side, nothing changes.
How can I change the behaviour of the bar, that the windows inside the application keep the same position when I dock left ?
(Problem is, that my windows are aligned on the right side of the application). When I dock the bar on the left, the windows are getting moved in the not visible area.)
View 2 Replies
View Related
Apr 20, 2014
Been trying to configure the GridView to display ony 4 rows of data at a time. I thought it wasn't working because I forgot to set AllowPaging to True, but after I did that, I just get the error of
The data source does not support server-side data paging.
Source Error:
Line 66: titlesGridView.DataBind(); // displays query results
Here is my Books.aspx.cs code:
// Fig. 29.11: Books.aspx.cs
// Code-behind file for the password-protected Books page.
using System;
using System.Data.Entity;
using System.Linq;
namespace Bug2Bug.ProtectedContent {
public partial class Books : System.Web.UI.Page {
[Code] ....
Am I missing anything or doing something wrong thats not causing it to page & only display 4 titles at a time?
View 2 Replies
View Related
Aug 25, 2013
I am attempting to break up a file into smaller chunks and have it process the different parts of the file in parallel to speed up the entire process. I was thinking maybe 4 chunks at a time. How do I get my program to do this? Is there a good book explaining parallel processing in C?
View 7 Replies
View Related
Jan 21, 2015
I wrote the following program:
#include "stdafx.h"
#include "string.h"
#include "ctype.h"
[Code].....
View 1 Replies
View Related