Project

General

Profile

Actions

Bug #3203

closed

Don't assume pthread_t is a pointer

Added by tkusumi over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
08/30/2019
Due date:
% Done:

0%

Estimated time:

Description

A pthread_t variable doesn't need to be initialized with NULL prior to calling pthread_create(3).
This also isn't portable since pthread_t is an opaque type (i.e. may not be a pointer, and in fact it's not on Linux/glibc).

  1. grep "thread = NULL" sbin/hammer2 rI
    sbin/hammer2/subs.c: pthread_t thread = NULL;
    sbin/hammer2/cmd_service.c: thread = NULL;
    sbin/hammer2/cmd_service.c: thread = NULL;
    sbin/hammer2/cmd_service.c: thread = NULL;
    sbin/hammer2/cmd_service.c: conf
    >thread = NULL;
    sbin/hammer2/cmd_service.c: conf->iocom_thread = NULL;
    sbin/hammer2/cmd_service.c: thread = NULL;

It looks like above exists for this conditional below.
If this could be rewritten without testing pthread_t itself (it shouldn't be too), NULL initialization could be removed.

369                 if (conf->thread == NULL) {
370 fprintf(stderr, "VOLCONF THREAD STARTED\n");
371 pthread_cond_init(&conf->cond, NULL);
372 pthread_create(&conf->thread, NULL,
373 hammer2_volconf_thread, (void *)conf);
374 }
Actions #1

Updated by tkusumi over 4 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF