At last we found the sollution
Since the objective will be to sync threads
to interact with the buffer, the buffer
needs to be placed in a shared memory place
Being so the malloc idea is quite a bad one
A straight forward array is the correct
choice
instead of the
char* buffer = malloc (4096 * sizeof (char))
we need to use
...
User Profile
Collapse
-
here is the relevant code to understand the problem:
...Code:message struct: typedef struct block_t{ int op; int blockId; char blockContents[BLOCK_SIZE]; } block_server_packet_t; server: ... if(message->op == op_read){ buffer_t_erase(message->blockContents); strcpy(message->blockContents, *(blocos + (message->blockId)));Leave a comment:
-
Block Server Study Case
Hi there
In order to retrieve info from a specific block
we pass a buffer to a function
the header of the function is
read_block (BlockId, char* buffer)
however when we access the info in the block
and we try to copy its info to the buffer it goes
into Segmentation Fault
buffer is
char* buffer = malloc (4096 * sizeof (char))
... -
Problem reading from stdin
Hi.
I want to read several words from stdin (save them in string) and then process this string.
The problem is that my code works for the first time but when i finish processing i cannot read a new string from stdin, it enters in an infinite loop, printing Request.
...Code:while(1) { printf("\nRequest\n>"); if(fgets(string, sizeof(string), stdin)!=NULL) { sscanf(string,"%s",comand);
No activity results to display
Show More
Leave a comment: