-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add fix timer race code #412
base: master
Are you sure you want to change the base?
Conversation
/azp run #Resolved |
Azure Pipelines successfully started running 1 pipeline(s). #Resolved |
/azp run #Resolved |
Azure Pipelines successfully started running 1 pipeline(s). #Resolved |
interfaces/inc/c_pal/threadpool.h
Outdated
@@ -21,10 +21,13 @@ extern "C" { | |||
#endif | |||
|
|||
typedef struct THREADPOOL_TAG THREADPOOL; | |||
typedef struct TIMER_INSTANCE_TAG* TIMER_INSTANCE_HANDLE; | |||
typedef struct TIMER_INSTANCE_TAG TIMER_INSTANCE; | |||
typedef struct TIMER_INSTANCE_TAG* TIMER_INSTANCE_HANDLE; //todo: if this one is needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably remove TIMER_INSTANCE_HANDLE #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not removed, I can still see it.
|
||
MOCKABLE_FUNCTION(, int, threadpool_timer_restart, TIMER_INSTANCE_HANDLE, timer, uint32_t, start_delay_ms, uint32_t, timer_period_ms); | ||
MOCKABLE_FUNCTION(, int, threadpool_timer_restart, THANDLE(TIMER_INSTANCE)*, timer, uint32_t, start_delay_ms, uint32_t, timer_period_ms); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -1140,9 +1141,10 @@ TEST_FUNCTION(threadpool_timer_start_with_NULL_work_function_context_succeeds) | |||
// arrange | |||
THANDLE(THREADPOOL) threadpool = test_create_and_open_threadpool(); | |||
|
|||
TIMER_INSTANCE_HANDLE timer_instance; | |||
THANDLE(TIMER_INSTANCE) timer_instance = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will getting segmentation fault if not set this THANDLE to NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The common pattern we have in the code that uses this is
typedef struct SOME_STRUCT_TAG
{
// ...
THANDLE(TIMER_INSTANCE) timer;
// ...
} SOME_STRUCT;
// then in the "_create" function:
SOME_STRUCT_HANDLE result = (SOME_STRUCT_HANDLE)malloc(sizeof(SOME_STRUCT);
threadpool_timer_start(threadpool, start_delay, period, test_work_function, context, &result->timer);
The timer is being passed in uninitialized, and so requiring it to be initialized in the test implies that the above pattern will need to change. BTW, this comment goes along with using THANDLE_INITIALIZE_MOVE
instead of THANDLE_MOVE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified to initialize_move
win32/src/threadpool_win32.c
Outdated
threadpool_internal_set_timer(tp_timer, start_delay_ms, timer_period_ms); | ||
|
||
/* Codes_SRS_THREADPOOL_WIN32_42_009: [ threadpool_timer_start shall return the allocated handle in timer_handle. ]*/ | ||
THANDLE_MOVE(TIMER_INSTANCE)(timer_handle, &timer_temp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -18,8 +18,7 @@ | |||
threadpool_schedule_work, \ | |||
threadpool_timer_start, \ | |||
threadpool_timer_restart, \ | |||
threadpool_timer_cancel, \ | |||
threadpool_timer_destroy \ | |||
threadpool_timer_cancel | |||
) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build failed, missing \
at the end of this line #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
No pipelines are associated with this pull request. #Resolved |
1 similar comment
No pipelines are associated with this pull request. #Resolved |
/azp run #Resolved |
Azure Pipelines successfully started running 1 pipeline(s). #Resolved |
/azp run #Resolved |
Azure Pipelines successfully started running 1 pipeline(s). #Resolved |
interfaces/inc/c_pal/threadpool.h
Outdated
@@ -21,10 +21,13 @@ extern "C" { | |||
#endif | |||
|
|||
typedef struct THREADPOOL_TAG THREADPOOL; | |||
typedef struct TIMER_INSTANCE_TAG TIMER_INSTANCE; | |||
typedef struct TIMER_INSTANCE_TAG* TIMER_INSTANCE_HANDLE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or are there more PRs planned? If so, we should add a comment explaining that, otherwise it is sort of confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the timer_instance_handle, not using anymore
for (uint32_t i = 0; i < N_TIMERS; i++) | ||
{ | ||
ASSERT_ARE_EQUAL(int, 0, threadpool_timer_start(threadpool, 100, 500, work_function, (void*)&call_count, &timers[i])); | ||
THANDLE_INITIALIZE(TIMER_INSTANCE)((void*) & timers[i], NULL); | ||
ASSERT_ARE_EQUAL(int, 0, threadpool_timer_start(threadpool, 100, 500, work_function, (void*)&call_count, (void*) & timers[i])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed
(void)InterlockedDecrement(&chaos_test_data->timers_starting); | ||
WakeByAddressSingle((PVOID)&chaos_test_data->timers_starting); | ||
} | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
(void)InterlockedDecrement(&chaos_test_data->timers_starting); | ||
WakeByAddressSingle((PVOID)&chaos_test_data->timers_starting); | ||
} | ||
case TEST_ACTION_SCHEDULE_WORK_ITEM: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing break; #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
if (threadpool_schedule_work_item(chaos_test_data->threadpool, chaos_test_data->work_item_context) == 0) | ||
{ | ||
(void)InterlockedIncrement64(&chaos_test_data->expected_call_count); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
Here and below. In reply to: 2487086153 Refers to: win32/tests/threadpool_win32_int/threadpool_win32_int.c:1064 in 491e0ff. [](commit_id = 491e0ff, deletion_comment = False) |
@@ -1008,12 +1099,9 @@ static DWORD WINAPI chaos_thread_with_timers_no_lock_func(LPVOID lpThreadParamet | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
// assert that all scheduled items were executed | ||
ASSERT_ARE_EQUAL(int64_t, (int64_t)InterlockedAdd64(&chaos_test_data.expected_call_count, 0), (int64_t)InterlockedAdd64(&chaos_test_data.executed_work_functions, 0)); | ||
|
||
LogInfo("Chaos test executed %" PRIu64 " work items, %" PRIu64 " timers", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
I think the same chaos tests should be run on Linux also. Unit tests should be different, but at integration level we should be running exactly the same test code on both platforms and it should pass .... Refers to: linux/tests/threadpool_linux_int/threadpool_linux_int.c:869 in 491e0ff. [](commit_id = 491e0ff, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
Pull request contains merge conflicts. #Resolved |
1 similar comment
Pull request contains merge conflicts. #Resolved |
done In reply to: 2487086295 Refers to: win32/tests/threadpool_win32_int/threadpool_win32_int.c:1064 in 491e0ff. [](commit_id = 491e0ff, deletion_comment = False) |
/azp run |
Pull request contains merge conflicts. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
No description provided.