in reply to [Win32] pthreads and memory allocation
There is nothing returned from this C subroutine,
void *TaskCode(void *argument).
tid = *((int *) argument);
means: argument is "cast" as a pointer to integer.
Then that result is de-referenced to get the "tid". A **int.
The OP's code is a memory leak because there is no pointer or other way to use the memory allocated by
"s = (char*) malloc(100);".
"s" is a memory pointer returned by malloc(). Now a malloc() call should have a conditional statement to see that it actually worked. But the big thing here is that the subroutine TaskCode() returns bullshit. I don't see how "s", the pointer to a new memory allocation of 100 bytes can ever be used outside of TaskCode()void *TaskCode(void *argument) { int tid; char * s; tid = *((int *) argument); // tid = **argument; printf("thread %d: calling malloc\n", tid); s = (char*) malloc(100); printf("thread %d: malloc called\n", tid); return NULL; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [Win32] pthreads and memory allocation
by syphilis (Archbishop) on Nov 22, 2011 at 07:22 UTC | |
by Marshall (Canon) on Nov 22, 2011 at 08:28 UTC |