Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Lock prefix?

Featured Replies

Posted

What is this used for? And is there C++/C code that when compiled uses this(to give a better understanding of it)?

I checked the help file but I don't really get what it is used for. Is there an unlock?

I am probably getting confused due to the lack of knowing more about how the cpu/etc interact, etc.

It allows an instruction to complete without any chance of interruption. There is no need for an "unlock" because the lock lasts only as long as the instruction takes to execute.

This is very important for multi-CPU environments, since it allows one CPU to guarantee that it has written the required value to that memory location, before any other CPU can either read or write that same memory location.

recently read about it. it's another instruction to get cleaner/shorter syntax... just like 'using' for example.

void SomeMethod() {
lock (this) {
// do some stuff
}
}

will generate the same code as

void SomeMethod() {
object oTemp = this;
Monitor.Enter(oTemp);
try {
// do some stuff
}
finally {
Monitor.Exit(oTemp);
}
}

peter already told about its use cases.

  • Author

Okay I think I get it.

So the C++ one sets a bool using the lock instruction so that no other cpus access it before the lock is in place?

What is this used for? And is there C++/C code that when compiled uses this(to give a better understanding of it)?

I checked the help file but I don't really get what it is used for. Is there an unlock?

I am probably getting confused due to the lack of knowing more about how the cpu/etc interact, etc.

C++ has the similar effect using API:

- EnterCriticalSection

- LeaveCriticalSection

and others.

More information:

http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx

And for more info on lock in C#:

http://msdn.microsoft.com/en-us/library/c5kehkcz(VS.71).aspx
What is this used for? And is there C++/C code that when compiled uses this(to give a better understanding of it)?

I checked the help file but I don't really get what it is used for. Is there an unlock?

I am probably getting confused due to the lack of knowing more about how the cpu/etc interact, etc.

C++ has the similar effect using API:

- EnterCriticalSection

- LeaveCriticalSection

and others.

More information:

http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx

And for more info on lock in C#:

http://msdn.microsoft.com/en-us/library/c5kehkcz(VS.71).aspx

Though, critical sections are limited to Windows environments (Which is a given, due to the link to MSDN), where as the LOCK or Try/Finally statement should function cross-platform.

Though, critical sections are limited to Windows environments (Which is a given, due to the link to MSDN), where as the LOCK or Try/Finally statement should function cross-platform.

Users on other platforms can use their OS specific similar API/functions to handle the differences. While the names of things wont be the same, the overall purpose and result will be similar. Such as, Linux users can use the following to do the similar effect of critical sections:

EnterCriticalSection (win32) -> pthread_mutex_lock (Linux)

LeaveCriticalSection (win32) -> pthread_mutex_trylock (Linux)

DeleteCriticalSection (win32) -> pthread_mutex_destroy (Linux)

There will be slight differences doing it that way since win32 critical sections are specific to the process using the API, while mutex threads can go cross-process. But you can construct functions to pretty much emulate the critical section API on win32 to prevent cross-process access if the need is there.

I mainly pointed out the critical sections based on high6's question, since .NET (C# lock) is specific to Win32.

Though, critical sections are limited to Windows environments (Which is a given, due to the link to MSDN), where as the LOCK or Try/Finally statement should function cross-platform.

Users on other platforms can use their OS specific similar API/functions to handle the differences. While the names of things wont be the same, the overall purpose and result will be similar. Such as, Linux users can use the following to do the similar effect of critical sections:

EnterCriticalSection (win32) -> pthread_mutex_lock (Linux)

LeaveCriticalSection (win32) -> pthread_mutex_trylock (Linux)

DeleteCriticalSection (win32) -> pthread_mutex_destroy (Linux)

There will be slight differences doing it that way since win32 critical sections are specific to the process using the API, while mutex threads can go cross-process. But you can construct functions to pretty much emulate the critical section API on win32 to prevent cross-process access if the need is there.

I mainly pointed out the critical sections based on high6's question, since .NET (C# lock) is specific to Win32.

I well understood your purpose, I was just leaving notes for future users whom may be writing on a non-Windows platform (i.e.: Any number of Linux or UNIX distro, among other possible environments).

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.