summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2012-01-13 17:41:17 +0530
committerRaghavendra Bhat <raghavendrabhat@gluster.com>2012-01-13 17:44:01 +0530
commit15472c449d9da05fc1a4277d82c6c2126ae4b81d (patch)
tree7bf23785eb51953912645ce89b12764470d4ff06
parent254e67dbd7a35d38dbe7a5f525955adeb86f5939 (diff)
ping_pong: allocate the memory from heap instead of using the stack address
Currently the stack address of the structure which holds information about the number of locks, fd etc is passed to the thread doing the locking. Instead of sending the stack address, allocate memory from the heap and use that address to send to the other thread. Change-Id: I417e22aee0eed1fa921982e78239147553886786 Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com>
-rw-r--r--c_pgms/ping_pong.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/c_pgms/ping_pong.c b/c_pgms/ping_pong.c
index 7881266..90141cf 100644
--- a/c_pgms/ping_pong.c
+++ b/c_pgms/ping_pong.c
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
char *fname;
int fd, num_locks;
int c;
- file_info_t info_file;
+ file_info_t *info_file = NULL;
pthread_t thread;
int tid = -1;
int zzzz = 600;
@@ -247,10 +247,16 @@ int main(int argc, char *argv[])
fd = open(fname, O_CREAT|O_RDWR, 0600);
if (fd == -1) exit(1);
- info_file.fd = fd;
- info_file.num_locks = num_locks;
+ info_file = calloc (1, sizeof (*info_file));
+ if (!info_file) {
+ ret = -1;
+ goto out;
+ }
+
+ info_file->fd = fd;
+ info_file->num_locks = num_locks;
- tid = pthread_create (&thread, NULL, (void *)ping_pong, (void *)&info_file);
+ tid = pthread_create (&thread, NULL, (void *)ping_pong, (void *)info_file);
if (zzzz == 0) {
printf ("running indefinitely\n");