Skip to content

No recovery mechanism from Thread instantiation faillure #2024

Closed
@pan-

Description

@pan-

Instantiating an object of type Thread will start the thread immediately.

If the thread can't be started then the system will enter in error state.

It should be possible to use the c++ Thread wrapper and recover from errors if the thread can't be started.

One solution could be to not start the thread at instantiation point but instead let the user start it explicitly by calling the function Thread::start.

Another solution would be to embed a status in the Thread object which allow to verify if the thread is started or not after its instantiation.

class Thread { 

    bool is_running();

    operator bool() { 
        return is_running();
    }
};

This change preserve backward compatibility and let the user write simple code like this:

Thread my_thread(do_something);
if (!my_thread) { 
   // thread not started
   // recovery here
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions