-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: jano Differential Revision: D68632411 fbshipit-source-id: 8527d255e871e07bc6df258cc58c046db5aa680b
- Loading branch information
1 parent
1a98e72
commit a2466c5
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?hh | ||
|
||
async function thread_func() { | ||
echo "thread\n"; | ||
|
||
await HH\SimpleLock\lock('thread_lock1'); | ||
await HH\SimpleLock\lock('thread_lock2'); | ||
await HH\SimpleLock\lock('end_lock'); | ||
|
||
echo 'thread: '; var_dump(HH\SimpleLock\is_held('main_lock1')); | ||
echo 'thread: '; var_dump(HH\SimpleLock\is_held('main_lock2')); | ||
echo 'thread: '; var_dump(HH\SimpleLock\is_held('thread_lock1')); | ||
echo 'thread: '; var_dump(HH\SimpleLock\is_held('thread_lock2')); | ||
|
||
$_ = true; | ||
$t = apc_inc('threads', 1, inout $_); | ||
|
||
await HH\SimpleLock\lock('sync'); | ||
HH\SimpleLock\unlock('thread_lock2'); | ||
} | ||
|
||
function thread_main() { | ||
HH\Asio\join(thread_func()); | ||
} | ||
|
||
<<__EntryPoint>> | ||
async function main() { | ||
if (HH\execution_context() === "xbox") return; | ||
|
||
await HH\SimpleLock\lock('main_lock1'); | ||
await HH\SimpleLock\lock('main_lock2'); | ||
await HH\SimpleLock\lock('sync'); | ||
apc_store('threads', 0); | ||
|
||
$func = fb_call_user_func_async( | ||
__FILE__, | ||
'thread_main' | ||
); | ||
|
||
$_ = true; | ||
while (apc_fetch('threads', inout $_) !== 1) usleep(10); | ||
|
||
echo 'main: '; var_dump(HH\SimpleLock\is_held('main_lock1')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('main_lock2')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('thread_lock1')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('thread_lock2')); | ||
|
||
HH\SimpleLock\unlock('sync'); | ||
fb_end_user_func_async($func); | ||
|
||
HH\SimpleLock\unlock('main_lock2'); | ||
await HH\SimpleLock\lock('end_lock'); | ||
|
||
echo 'main: '; var_dump(HH\SimpleLock\is_held('main_lock1')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('main_lock2')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('thread_lock1')); | ||
echo 'main: '; var_dump(HH\SimpleLock\is_held('thread_lock2')); | ||
|
||
echo "Main done.\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
thread | ||
thread: bool(true) | ||
thread: bool(true) | ||
thread: bool(true) | ||
thread: bool(true) | ||
main: bool(true) | ||
main: bool(true) | ||
main: bool(true) | ||
main: bool(true) | ||
main: bool(true) | ||
main: bool(false) | ||
main: bool(false) | ||
main: bool(false) | ||
Main done. |
Empty file.