synchronization

is volatile of no use on x86 processors

谁都会走 提交于 2019-12-06 15:42:18
问题 I read somewhere that x86 processors have cache coherency and can sync the value of fields across multiple cores anyway on each write. Does that mean that we can code without using the 'volatile' keywoard in java if we plan on running only on x86 processors? Update: Ok assuming that we leave out the issue of instruction reordering, can we assume that the issue of an assignment to a non-volatile field not being visible across cores is not present on x86 processors? 回答1: No -- the volatile

Java: how volatile guarantee visibility of “data” in this piece of code?

两盒软妹~` 提交于 2019-12-06 15:06:19
问题 Class Future { private volatile boolean ready; private Object data; public Object get() { if(!ready) return null; return data; } public synchronized void setOnce(Object o) { if(ready) throw...; data = o; ready = true; } } It said "if a thread reads data, there is a happens-before edge from write to read of that guarantees visibility of data" I know from my learning: volatile ensures that every read/write will be in the memory instead of only in cache or registers; volatile ensures reorder:

How can I change StoreGeneratedPattern and force Entity Framework to generate insert statement with identity

妖精的绣舞 提交于 2019-12-06 14:47:33
问题 I have server and client database where I need to keep some of the server data in sync with client dataabse. Database schema is same apart from having IDENTITY(1,1) on server. Data can be created on server only. It has to be inserted on client with using server's id. CREATE TABLE [MyServer].[dbo].[Test1]( [Test1Id] [int] IDENTITY(1,1) NOT NULL, [Test1Value] [datetime] NOT NULL, CONSTRAINT [PK_Test1] PRIMARY KEY CLUSTERED ( [Test1Id] ASC ) ) ON [PRIMARY] CREATE TABLE [MyClient].[dbo].[Test1](

How to Synchronize SQLServer Database and MySQL Database

浪子不回头ぞ 提交于 2019-12-06 13:44:58
问题 My Scenario: I have two applications. First one is a website which is connected to MySQL Database and 2nd one is a Desktop Application which is connected to SQL Server2008 R2 Database. The Desktop application updates records locally and the MySQL database is updated online though the website. Problem: Two different databases, how can we update at the spot when changes are made either in MySQL or SQL Database? What I Want: Databases should be synchronized to each other (e.g. if changes are

Shared_ptr and Memory Visibility in c++

空扰寡人 提交于 2019-12-06 13:27:25
If you heap allocate an object with shared_ptr on thread A , then copy the shared_ptr to another thread without any synchronization. Is the other thread guaranteed to see a fully constructed object? int main(){ auto sp = std::make_shared<int>(5); auto f=std::async(std::launch::async, [sp](){ std::cout<<*sp;}); } Is it guaranteed to print 5? In your example, the shared_ptr object has been duplicated before std::async returns, hence it still exists in the new thread even if the original shared_ptr is destroyed before the second thread accesses it's copy. So, the answer is yes. You are passing by

How can I synchronize asyncio with other OS threads?

戏子无情 提交于 2019-12-06 13:01:41
I have a program with one main thread where I spawn a second thread that uses asyncio. Are there any tools provided to synchronize these two threads? If everything was asyncio, I could do it with its synchronization primitives, eg: import asyncio async def taskA(lst, evt): print(f'Appending 1') lst.append(1) evt.set() async def taskB(lst, evt): await evt.wait() print('Retrieved:', lst.pop()) lst = [] evt = asyncio.Event() asyncio.get_event_loop().run_until_complete(asyncio.gather( taskA(lst, evt), taskB(lst, evt), )) However, this does not work with multiple threads. If I just use a threading

Synchronizing databases

白昼怎懂夜的黑 提交于 2019-12-06 12:20:35
问题 I am developing an Adobe AIR application which stores data locally using a SQLite database. At any time, I want the end user to synchronize his/her local data to a central MySQL database. Any tips, advice for getting this right? Performance and stability is the key (besides security ;)) 回答1: I can think of a couple of ways: Periodically, Dump your MySQL database and create a new SQLite database from the dump. You can then serve the SQLite database (SQLite databases are contained in a single

Thoughts about rendering loop strategies

六眼飞鱼酱① 提交于 2019-12-06 12:03:23
I know that hundreds of variations of these considerations have been posted all over the net. However, I haven't found anything that adresses my exact problem, so I hope you can help me see the light. I'm currently toying with 2D game development in Java using OpenGL. The language and graphics library used is not that relevant to my question though as it has a more general character. I'm attempting to design a general purpose game loop which can be used more or less as is for any game that has moderately heavy graphics (mostly bitmap textures) and possibly even heavier game logic (AI,

How does threads sleep with interrupt disabled?

风格不统一 提交于 2019-12-06 11:50:09
问题 I am trying to understand how the code below works. This is straight out of my profs lecture slides. This P() and V() function is the part of semaphore implementation in the OS that we use in class (OS161). I think you might need understanding of the OS161 to answer my question, since its widely used, hopefully some one can answer this questions. My understanding of this code with lecture notes: X:Flow of the P() function 1. When a thread call P(), we disable interrupt 2. check if we have any

API to set file timestamps in OS X

▼魔方 西西 提交于 2019-12-06 11:39:30
问题 I want to (bidirectionally) synchronize files between a PC (Win7, NTFS) and a Mac (OS X, HFS+). I have tried using a lot of existing tools / methods (Unison, SyncToy or other software working over Samba shares etc.) but none of them are able to preserve the file creation timestamps (hence-forward referred to as FCTs) on my files, which is unacceptable to me. Unison doesn't understand the notion of FCTs, perhaps because it was primarily built with Unix in mind (See my Unison forum post)