Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:33:11+00:00 2026-06-04T14:33:11+00:00

I am pretty new to multi-threading in general and I would like to know

  • 0

I am pretty new to multi-threading in general and I would like to know how can I lock a shared integer variable to not be accessed by other threads while it is read/updated by an other thread.

When I try do do SyncLock myInteger, I get that error : Error 6 ‘SyncLock’ operand cannot be of type ‘Integer’ because ‘Integer’ is not a reference type.

Here a simplified example of what I mean

Private Shared myInteger As Integer

Private Sub MySub()
  SyncLock myInteger ' This does not work
    ' read/write a new value to myInteger
  End SyncLock
End Sub

MySub is called by multiple instances of the class, and running in multiple threads

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:33:12+00:00Added an answer on June 4, 2026 at 2:33 pm

    I suspect you don’t fully understand what SyncLock does. Even if you could do it (if Integer were a reference type, for example) you wouldn’t want to do it – because when you replaced the value of myInteger, the lock would be useless.

    You should either lock on something else (personally I generally declare a separate, read-only variable purely for the sake of locking, usually of type Object) or if you only want to operate on myInteger at any time (rather than some compound operation which needs to read or update several variables at the same time), use the Interlocked class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C# Captured Variable In Loop I am pretty new to multi-threading programming.
My multi-threading knowledge is still pretty rudimentary, so would really appreciate some pointers here.
I'm pretty new to QGraphicsView in Qt. As far as I can tell there
I'm pretty new to programming for Linux environments, so I don't exactly know what
I'm a pretty new C# programmer. I was wondering if someone can fill me
Pretty new here. But before I ask my question, I'm not looking for teh
Im pretty new to Linux in general. Ive just been following this tutorial(http://net.tutsplus.com/tutorials/php/how-to-setup-a-dedicated-web-server-for-free/) to
My question might sound a bit naive but I'm pretty new with multi-threaded programming.
Hi I'm pretty new to Python, so I'm not really aware of all the
Pretty new flixel/AS3 user here, though not entirely new to coding. Anyways, the error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.