summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGentoo <installgentoo@endianness.com>2020-08-27 10:08:10 +1000
committerGentoo <installgentoo@endianness.com>2020-08-27 10:08:10 +1000
commitc3f1ebf75de0b6e038c05c33544a58da97b64df7 (patch)
treecd0e0ad5be214a29ac4341aa1aa19bf3f8c92f53
parentb467cf03c0c7aba9cdcd62045c7ed2e0cc897d5e (diff)
downloadsleep-sort-c3f1ebf75de0b6e038c05c33544a58da97b64df7.tar.gz
sleep-sort-c3f1ebf75de0b6e038c05c33544a58da97b64df7.tar.bz2
sleep-sort-c3f1ebf75de0b6e038c05c33544a58da97b64df7.zip
change deref into cast
-rw-r--r--main.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/main.c b/main.c
index 2d9d97c..a382e69 100644
--- a/main.c
+++ b/main.c
@@ -12,7 +12,7 @@ int counter = 0;
void *sleepMe(int64_t *p)
{
- int64_t n = (int64_t)p;//cast the 64 bit pointer to a 64 bit int
+ int64_t n = *p;
usleep(n*500);//*200 will do, but *500 is needed to reliably attain a correct order for numbers only 1 apart
pthread_mutex_lock(&lock);
@@ -26,7 +26,7 @@ int main()
int c = NUM_THREADS;//number of threads to create
int thread = 0;
- while (c--){pthread_create(&threads[thread++], NULL, (void *)sleepMe, (int64_t *)sortMe[c]);}//create a thread for each number in the array
+ while (c--){pthread_create(&threads[thread++], NULL, (void *)sleepMe, &sortMe[c]);}//create a thread for each number in the array
for (int i = 0; i < thread; ++i){pthread_join(threads[i], NULL);}//join all the threads, when all are joined, writing to the result array is done