C :: Can't Get Mutual Exclusion To Work
Nov 4, 2013
I have a program that spawns a number of threads. Each thread generates a table of output. During the time that it is creating this output, I don't want the other threads to be outputting, so I've attempted to create a mutex semaphore to allow only one thread at time to ouput.
Code:
sem_t mutex;
void* node(void *thread_arg) {
// set a mutex lock to allow the output for this next step to complete for this thread
sem_wait(&mutex);
// generate table with various fprintf statements
}
[code]....
This approach isn't working.
View 3 Replies
ADVERTISEMENT
Oct 26, 2014
This is my semaphore, i want to improve this code with mutual exlusion:
semaphore(){
int cont;
mutex lock;
Condic condit();
down(){
lock.acquire();
[Code] .....
I found that one way is with TSL Test and set Lock, but i couldn't find the way to call it in C. Then i found the windows call enterCriticalRegion but it's not what i want.
View 4 Replies
View Related
Nov 14, 2013
I've just started learning from "Jumping into C++". Great book. Unfortunately, I've also encountered my first snag. Practice problem number 3 from chapter 4 tells me to make a small calculator that takes one of the four arithmetic operations and its two arguments as input and give the result as output. Here's what my newbie mind came up with:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
[Code] .....
The thing that I don't get is why doesn't the function "getline" work. It's worked in previous programs. The program seems to work if I simply replace getline with a simple "cin". I could easily use that as a cheap fix but I am interested in knowing why "getline" refuses to work anymore....
View 3 Replies
View Related
Feb 7, 2014
what I do I cannot get a division to work:
Code:
//END RANGE INPUT
long double End;
printf("
Please enter the start of the range (Lower Bound):
");
[Code]...
No matter what I input for the values of 'Start', 'End' and 'Interval', the value of 'SizeL' always seems to be -2.
View 8 Replies
View Related
Apr 9, 2014
I am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.
The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:
Code:
#define EMPTY 0
#define X 1
#define O 2 Here is my function: Code: int check_state(int board[3][3]) {
int winner = 0;
[Code].....
View 1 Replies
View Related
Sep 24, 2013
I just dont see what the issue is here. I have stared at this thing forever. Im trying to make a calendar from scratch so I can be prepared for my second test on Friday.
Code:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i, n, s;
[Code]....
View 10 Replies
View Related
Nov 28, 2013
Assuming that we have the string :
Code:
***HELLO&SIR. & and * is the delimiters.
My question is how strtok will work in the beginning?
According to this to determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token. The scan also stops if the terminating null character is found.
This end of the token is automatically replaced by a null-character, and the beginning of the token is returned by the function. strtok will replace the first * with '' and the next call will start from the second * puts '' there and again the same with the third * ?
View 8 Replies
View Related
Aug 26, 2014
I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.
Code:
#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",
[Code]....
View 3 Replies
View Related
Mar 15, 2014
how the -bounds annotations work, and I came up with the following test program.The alloc_char function ensures maxRead/ maxSet(str) == len. This is, in turn, ensured by malloc and memset (see the comments; I found this in /usr/share/splint/lib/standard.h), but SPLint doesn't recognize that.However, SPLint correctly sees that requires maxRead(str) >= i is fulfilled in main.
Code:
/*
* splint -strict
*/
#include
#include
#include
#include
}
[code]....
(Of course the main function is contrived and I could use puts instead, but that's not the point. The point is to make it see that i is not out of bounds.)I have struggled with -bounds for a very long time. Earlier I gave up and used -likelybounds instead. But now I have written a library which is annotated for splint -strict with -likelybounds, and I want people to be able to use it with the full -bounds checks. I can't get those ensures and requires annotations for maxRead/Set to work.
View 2 Replies
View Related
Dec 31, 2014
puts(pd) does not give any output in the below code. Also, the first puts(ps) does give an output, but the second puts(ps) after "while" does not give any output.
Code:
#include <stdio.h>
int main()
{
char source[50]="Alice has apples.";
char destination[60];
char *pd, *ps;
}
[code].....
View 1 Replies
View Related
Mar 5, 2013
I have an issue getting boost libraries to work with QT IDE. Here are relevant lines from my .pro file...
INCLUDEPATH += c:/users/bob/desktop/boost_1_53_0/
LIBS += -LC:c:/users/bob/desktop/boost_1_53_0/stage/lib64
After adding #include <boost/filesystem.hpp> I get error...
C:UsersobDesktopqtpuntitled5mainwindow.cpp:3: error: C1083: Cannot open include file: 'boost/filesystem.hpp': No such file or directory
The IDE does not highlight the line. The error only appears on compilation.
View 2 Replies
View Related
Feb 28, 2015
I want to access the body of the Add() of a list in c# to see how it works, but it only just gives me the declaration.
[DebuggerTypeProxy(typeof (Mscorlib_CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
[Serializable]
public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable {
public void Add(T item); // thats all. I tried go to declaration but still gives me this line of code. This is from metadata in Visual studio.
}
How this thing work. It just a declaration not a definition yet its still doing something. How is that possible.
View 4 Replies
View Related
Nov 21, 2013
#include <iostream>
#include <string>
using namespace std ;
int main() {
string bored ;
do {
cout << " program" <<endl ;
[Code] .....
I made this as a simple do/while program, and if i run it, the second do/while statement will keep on going forever, without the [cin >> bored;] line working?
View 2 Replies
View Related
Jan 18, 2015
I am making a calculator where I will input 5 array of numbers and calculate those numbers with pointers or whatever you call it. I am getting an error like
note C:Dev-Cppincludec++3.4.2itsostream.tcc:63 candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
and more error if I try to fix the code. So yeah, can i have a hand?
Btw, here's my code.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
// function declaration:
void getAverage(int*);
void getSum(int*);
[Code] .....
View 7 Replies
View Related
Mar 21, 2014
I'm currently messing around with geolocation and have this Windows App I'm working on. There is no errors or warnings when I run it, but it does not work. I click my Enable GPS button and nada, nothing, zilch. This isn't a important project or anything just a learning experience for myself.
This is my C# portion if you need me to post the XAML side also I can do that as well.
using System;
using System.Collections.Generic;
using System.IO;
[Code].....
View 5 Replies
View Related
Jun 24, 2014
The opjective was to build an c# deskop windows application for an classic car sales company.
My job was the employees section of the application.
my problem is the following
i have 3 tabs
summary (overzicht)
details
mutation (muteren)
on the details tab i have 2 buttons and a search box both the buttons only do somthing on the summary tab where they also need to take the selected row to the field on the other tabs.
the search box is a text box that neds to find the valve in the summary tab and then als so select the full row and put it in the onther 2 tabs fields.
this is the code for the back en next buttons
private void btnback_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentRow.Index >= 1)
{
[Code]....
View 14 Replies
View Related
Mar 14, 2014
So, I've used int to float cast before. And it makes sense that it preserves the int value just converts it. I don't really need the answer, I'm just interested, and a resources could suffice.
1. Why in my test program it seems to preserve the int value, I expect that, but why for 0x8000 is it registering bit negation also. I know that is the negative bit for float, but it seems wrong. Is this an error in the gcc compiler conversion code?
2. What is the documentation on these type cast on how they actual work.
3. I know like no assembly, I'm wondering if some of the built in routines to handle or is it all c side code.
4. Can I convert type and preserve the bits. Maybe use void* casting ? I've never really bothered with void* so I don't all that I can do. Except be a pointer that doesn't know the type, obviously. I tested that out in the second code, the output doesn't seem correct, except -0.000. Is it working and my test numbers just are improper float format? It can't be that I test 0x3E20000 = 0.15625 from SingleWiki , but I got 1.328e-36 so the int to void* to float doesn't seem to work in the code below:
#include <cstdio>
int main(){
float flout;
unsigned int num = 1;
int ant;
printf("Int Shift float");
for(unsigned int shift=0;shift<32;shift++){
[Code] ....
View 5 Replies
View Related
Feb 25, 2013
I can not understand huge pointer, how its working.
#include<stdio.h>/ *How its working &decleration*/
int main(){
int huge *a =(int huge *)0x59990005;
int huge *b =(int huge *)0x59980015;
if(a == b)
printf("power of pointer");
else
printf("power of c");
return 0;
}
View 4 Replies
View Related
May 18, 2012
Why it's not working and how to make it work?
Code:
string str = "hello" + " *** ";
View 6 Replies
View Related
Nov 21, 2012
A student approached me and asked why his prime checker wouldn't work. I took a look and it should work, imo, for all < 64 bit inputs.
Code:
int isitprime(unsigned long long in) {
unsigned long long c;
unsigned long long max = sqrt(in);
if(in <= 1 )
[Code] .....
checked for a bunch of primes i could think of 0,1,2,3,4,5,6,7 up to 18446744073709551557, which is supposed to be one of the largest 64 bit primes. Worked.
View 5 Replies
View Related
May 21, 2013
This is my code for submitting students but when i use search function the course member is empty
Code: #include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#define SIZE 5
using std::cout;
using std::cin;
using namespace std;
int menu();
[code].....
View 11 Replies
View Related
Jun 9, 2014
I've implemented it a bit differently: I create 2 temporary arrays, one for the numbers lower from the pivot , an done for numbers greater then the pivot. in the end of each iteration the 2 arrays are copied to the original array:
Code: #include <iostream>
void QuickSort (int* A , int start, int end){
if (end-start<3){
return;
}
int mid=(start+end)/2;
int pivot=A[mid];
int lA[end-start] , rA[end-start], rCounter=0,lCounter=0;
int curr=0,i=start;
[code]....
View 3 Replies
View Related
Jun 3, 2013
This is the first time I'm working with 2d arrays and I have to read the pixels in the input file, then store the pixel from the input image file into the array. And there is a maximum width and height of 500. If the file's too big, then I have to print an error message. Also, my array should only be filled up to the dimensions of the input image file.
I have the code for everything up to that point but I'm not too sure how to approach this. I've defined max_width and height at the top of my file as 500 and I'm thinking of putting this part of the program into a new helper function. But I'm not completely sure how to start, I do know that the array would look something like this though:
int array[max_height][max_width].
1) the syntax of printing the error message/storing the values and 2) the values for my pixels in the input file are all in a single column; each value after the ppm format header is on a new line.
what the input file looks like:
Code:
P3
493 401
255
71
0
0
76
4
5
87
11
NOTE: First three lines are the header information for the ppm format; the numbers that follow go like this: red, green, blue, red, green, blue, etc.
View 1 Replies
View Related
Mar 20, 2013
i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example
Code:
int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5} but if i have this one
int group_id_local[max_j]={2,1,4,3};
// output should be {1,2,4,3}
/* COMPARE FUNCTION FOR USING QSORT()*/
int cmpfunc (const void* a, const void* b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;
[Code]....
why it will not sort the last element?
View 5 Replies
View Related
Dec 16, 2013
this programm should in theory create a labyrinth but it doesnt and i really dont have the skill to pick up where i have been mistaken so gcc runs it but it crashes and it doesnt produce any remarkable results even when it runs....
for example this should you run it with these parameters .
5
5
appear something like this
10111
10101
10101
10001
11111
or like this
10111
10001
11101
10001
11111
but it only crashes....it works with recursion and it makes a array (which is Ptr) a set of 1 and 0 which 0 is the path and 1 is the walls...
Code:
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int **Ptr;
int M, N, P, charge, i,c,j;
void Lab_creator(int vertical, int horizontal,int direction);
[Code] .....
View 2 Replies
View Related
Aug 17, 2013
I want to see how the command line arguments work. However I don't know how to enter this input. show me a method to see if my code works?
View 9 Replies
View Related