inplace_stop_callback could reduce its size by 2 pointers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
Cerca __inplace_stop_callback_base, inplace_stop_source::request_stop() e la deregistrazione dei callback. Traccia come vengono utilizzati i membri della lista e i membri relativi al completamento dell'esecuzione durante l'inserimento, l'esecuzione e la rimozione dei callback. Il lavoro è completato quando la sincronizzazione e il comportamento dei callback vengono preservati riducendo al contempo lo spazio di archiviazione della struttura come descritto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The __inplace_stop_callback_base structure is defined as follows:
struct __inplace_stop_callback_base {
const inplace_stop_source* __source_;
__execute_fn_t* __execute_;
__inplace_stop_callback_base* __next_ = nullptr;
__inplace_stop_callback_base** __prev_ptr_ = nullptr;
bool* __removed_during_callback_ = nullptr;
std::atomic<bool> __callback_completed_{false};
};
However, it's worth noting that there are two distinct phases of use of this data-structure:
- The callback is inserted in the linked-list of items, waiting to be executed
- The callback is actually being executed and needs synchronisation regarding the completion of the callback.
The data-members __removed_during_callback_ and __callback_completed_ are only ever used in the second phase and the data-members __next_ and __prev_ptr_ are only ever used in the first phase.
This means that these data-members can be placed into a union so that the storage for the next/prev pointers is reused for the removed/completed data-members during the second phase. Doing so would shrink the size of the __inplace_stop_callback_base structure from 6 pointers (48 bytes on 64-bit machines) to 4 pointers (32 bytes on 64-bit machines).
For example:
struct __inplace_stop_callback_base {
const inplace_stop_source* __source_;
__execute_fn_t* __execute_;
struct __list_members_t {
__inplace_stop_callback_base* __next_ = nullptr;
__inplace_stop_callback_base** __prev_ptr_ = nullptr;
};
struct __execute_members_t {
bool* __removed_during_callback_ = nullptr;
std::atomic<bool> __callback_completed_{false};
};
union {
__list_members_t __list_members_;
__execute_members_t __execute_members_;
};
};
The __execute_ data-member can be used as a discriminator to determine which data-members are active. The __execute_ member contains the function pointer that will be invoked and needs to be populated while the callback is sitting in the queue of callbacks to be invoked. However, we could set this data-member to nullptr when the function is being executed - we can take a copy of the function-pointer into a local variable inside inplace_stop_source::request_stop() and then set the __execute_ data-member to nullptr before initializing the __removed_during_callback_ and __callback_completed_ members. The __execute_ data-member can then be used by the callback deregistration to determine whether the callback is still a member of the list or has been or is in the process of being executed.
- Lingua principale
- C++
- Stelle
- 2.4k
- Fork
- 270
- Merge medio
- 2g 17h
- PR unite (30g)
- 37
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/stdexec
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 66/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
Tutte le issue di NVIDIA/stdexec
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
games-on-whales/wolf#509 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
bug-unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100