Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

janvorli
Copy link
Member

This change modifies the GCToEEInterface::CreateBackgroundThread so that it returns
a fully initialized and running thread.

@janvorli
Copy link
Member Author

@jkotas can you take a look please?

src/gc/gc.cpp Outdated
@@ -26879,26 +26818,10 @@ uint32_t gc_heap::bgc_thread_function()
BOOL do_exit = FALSE;
Thread* thread_to_destroy = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to move the DestroyThread call to the wrapper function as well, and remove DestroyThread from the gcenv headers (the other call to DestroyThread in gc_heap::kill_gc_thread is completely broken - it is not causing problems because this function is never called).

@jkotas
Copy link
Member

jkotas commented Jul 21, 2016

LGTM otherwise

cc @Maoni0 @swgillespie

@janvorli
Copy link
Member Author

@jkotas I've reflected your feedback, can you take another look please?


#ifdef FEATURE_REDHAWK
typedef uint32_t (__stdcall *BackgroundCallback)(void* pCallbackContext);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(BackgroundCallback callback, void* pCallbackContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can PalStartBackgroundGCThread can be removed as well?

@jkotas
Copy link
Member

jkotas commented Jul 21, 2016

👍

This change modifies the GCToEEInterface::CreateBackgroundThread so that it returns
a fully initialized and running thread.
@janvorli janvorli force-pushed the refactor-gc-thread-creation-2 branch from 27f89b7 to 0537929 Compare July 21, 2016 14:36
@janvorli
Copy link
Member Author

I've removed the PalStartBackgroundGCThread and squashed the commits

@jkotas jkotas merged commit 3b5550f into dotnet:master Jul 21, 2016
@janvorli janvorli deleted the refactor-gc-thread-creation-2 branch July 21, 2016 17:50
@Maoni0
Copy link
Member

Maoni0 commented Jul 21, 2016

We were not creating the equivalent of threadStartedEvent everytime we created a BGC thread - we just created one time and kept it. With the new code you are, could you restore the old behavior?

@jkotas
Copy link
Member

jkotas commented Jul 21, 2016

Why would you want to keep the event alive forever? I think it is better to create it just for the small window that it is needed.

@janvorli
Copy link
Member Author

@Maoni0 The code in GCToEEInterface where the event is used doesn't have any idea about GC heaps and that event was originally per heap. While I could keep that event in the hc_heap and pass it to the GCToEEInterface::CreateBackgroundThread as an additional parameter, that would be quite ugly, since the event has no meaning for the GC code anymore.

@Maoni0
Copy link
Member

Maoni0 commented Jul 21, 2016

you don't need to have the event in the gc_heap and pass it, you can just have the event stored in gcenv.ee.cpp. GC doesn't need to know about it at all. the event is likely needed forever because we'll likely keep doing BGCs but not frequent enough to keep the thread alive.

@janvorli
Copy link
Member Author

@Maoni0 so why was the event per heap before? Anyways, like @jkotas, I would prefer keeping it the new way.

@Maoni0
Copy link
Member

Maoni0 commented Jul 21, 2016

Thinking about this a bit more I think it's fine to keep it the way it is. We had different policies for server and workstation GC. for server we don't time out the threads so we'd only get into the situation of recreating the bgc thread in workstation case and there's no per heap there. But perhaps one day we may want to also timeout BGC threads for server then it would get kind of ugly to have to have code in gcenv.ee.cpp to recognize the difference between svr and wks.

@jkotas
Copy link
Member

jkotas commented Jul 21, 2016

Creating a new thread is several orders of magnitude more expensive operation than creating the event. So it is fine to create/close the event each time - there is no value in caching it.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
This change modifies the GCToEEInterface::CreateBackgroundThread so that it returns
a fully initialized and running thread.

Commit migrated from dotnet/coreclr@3b5550f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants