I'm working on a small wrapper library for a bigger project, and i've been killing my self over (what I think is) a pointer problem.
Here is the code (I extracted the part of the code where the problem is for better reading, I tested the code below, and I get the same problem):
wrapper.c
wrapper.h
tester.c
After compiling with 'gcc wrapper.c tester.c -o t -lpthread' .. I get some warnings.
When I execute './t' I get the output:
What I should get is a synchronized output, that is, the second thread waits for the first thread to complete, so the output should be:
I'm running this on a Windows environment using Cygwin.
You shot yourself in the foot right at the start. You can't return a pointer to memory on the stack and expect it to be valid when it goes out of scope.
Hello,
I have a signal handler which manipulates a data structure. The data structure's operations aren't atomic. So if two threads/processes are in a critical section at the same time the data structure will be broken.
With threads you can avoid this stuff with semaphores etc.
However,... (10 Replies)
Hello All,
I am having this issue...where I am actually having hard time understanding the problem:
The code is as follows:
#include<iostream.h>
void fxn(char*** var)
{
int i =4;
*var = (char**)malloc(i*sizeof(char*));
for(int j =0; j<4; j++)
{
*var = "name";
cout<<*var;... (6 Replies)
Hi all,
I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first).
#include <pthread.h>
#include "starter.h"
#include "UI.h"
Page* MM;
Page* Disk;
PCB* all_pcb_array;
void* display_prompt(void *id){
printf("Hello111\n");
return... (1 Reply)
Hi All,
I am using the array of pointers and storing the address of string.This is a global list.
So i am using extern to give the reference of this list to another file and using reading the data from this string.
But list is being corrupted and string is missing some characters in... (2 Replies)
Hello,
I run my pthread code on Linux with 4 processors. However, the speed up is only 2 times.
The code is about solving equation (G+s(i)C)z(i)=B*us(i), i=1,...,n. Here G,C are m*m matrix, B*us(i) is a m*1 vector and s(i) are n different numbers. I need to solve the equation n times to... (2 Replies)
hello
can any1 plz tell me about the system defined structures (like sysinfo) which wil give system and n/w charecteristics (ex: freeram in sysinfo). (1 Reply)
Hi all!
I am working on unix systems.I am programming in c.
I have got some problems with pthread.when I use pthread_create to creat a thread it says:
(.text+0x3a): undefined reference to `pthread_create'.
same is the problm with pthread_kill.
Can anyone help me out here.
Thanks.
vij. (2 Replies)
Hi All,
I was given a format of a file, and was asked to write a program which displays the data contained in the file in that purticular format.
Its all so confusing.
Please find the example of the format as well the code I have written in the attachment.
I hope any one of u guyz can... (0 Replies)
Dear friends
I have a bit basic doubts in pointers and the structures inter relationships.
the first one.
static struct apvt {
int dead;
int pending;
int abouttograb;
}*agents=NULL;
what agents pointer is... (1 Reply)